第一:
public class ManagerListener implements ServletContextListener {
public void contextDestroyed(ServletContextEvent arg0) {
}
public void contextInitialized(ServletContextEvent sce) {
ApplicationContext ctx = WebApplicationContextUtils
.getRequiredWebApplicationContext(sce.getServletContext());
SyncThread syncThread = new SyncThread();// 需要执行的线程
Thread thread = new Thread(syncThread);// 开启一个线程
thread.start();// 线程执行
System.out.println("监听器服务器起来");
}
}
第二:
@Component
public class SyncThread implements Runnable,ApplicationContextAware {
private Logger logger = LoggerFactory.getLogger(SyncThread.class);
public static ApplicationContext applicationContext;// 获取spring上下文
public void run() {
// 通过上下文获取产线信息service实体bean
SysConfigService sysConfigService = (SysConfigService) applicationContext
.getBean