function description:
when tomcat starts, a thread is started at the same time. Currently, there is no problem with thread startup, but a null pointer exception is caused due to the inability to inject javabean,. The javabean to be injected is encapsulated by itself and is used to implement specific functions. The class is annotated with @ Component and is also within the scanning range of package-scan. (note: SSM framework used)
the code is as follows:
@Controller
public class UDPServer implements ServletContextListener {
// Bean
@Autowired
UDPThread udpThread;
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
// Bean
udpThread.execute();
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
}
}