我的主要代码
public static void main(String[] args) {
System.out.println("Hello World!");
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"DataSource.xml");
App app = applicationContext.getBean(App.class);
app.start();
}
还有我的启动方法
public void start() {
try {
ServerSocket mobCom = new ServerSocket(9846);
ExecutorService executorService = Executors.newCachedThreadPool();
while (true) {
Socket socket = mobCom.accept();
PortService portService = new PortService(socket);
executorService.submit(portService);
}
} catch (IOException e) {
e.printStackTrace();
}
}
但是我希望 PortService 对象是从 Spring 而不是直接创建的,因为它具有用于通信的 db 类。我该怎么做。