public class ScheduleController  implements ServletContextListener {
@Autowired
private ScheduleService scheduleService; @Override
public void contextDestroyed(ServletContextEvent event) {
System.out.println("销毁");
} @Override
public void contextInitialized(ServletContextEvent event) {
WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext())
.getAutowireCapableBeanFactory().autowireBean(this);
System.out.println("开始执行周期任务");
scheduleService.start(); ;
}
}

如果使用ServletContextListener对spring启动前和停止前做一些清理工作的时时候,需要用到一些autowired的类,测试发现这些类在启动的时候,由于相应的beanfactory还没有加载,所以会出现问题。

最新文章

  1. visual stdio 2015安装配置及原理
  2. windows下打包react-native应用程序
  3. iOS播放铃声及震动,适用于扫描、新消息等
  4. BZOJ-1880 Elaxia的路线 SPFA+枚举
  5. juery动态添加和删除
  6. Linux下查看用户列表
  7. ubuntu 修改ssh远程主机名称,mac开机运行命令,静默方式启动virtual box虚拟机,静默执行run脚本
  8. php生成代金券码
  9. netcore程序部署到docker
  10. autpmapper映射忽略某个属性
  11. Python3 Tcp未发送/接收完数据即被RST处理办法
  12. VMware与Centos系统安装、重置root密码
  13. ubuntu15.04中安装mysql和mysql-workbench
  14. python3_unittest单元测试框架
  15. node制作代理服务器
  16. Google Breakpad 完全解析(二) —— Windows前台实现篇
  17. list!=null跟list.isEmpty()有什么区别?
  18. gym - 101673I Twenty Four, Again (表达式树枚举)
  19. Bicoloring UVA - 10004 二分图判断
  20. 获取Android设备无线和以太网MAC地址

热门文章

  1. 160--Intersection Of Two Linked List
  2. Nios II IDE代码优化,quartus ii 11.0版本IDE
  3. springboot easypoi 报错The bean 'beanNameViewResolver', defined in class path resource [cn/afterturn/e
  4. Codeforces H. Kilani and the Game(多源BFS)
  5. 使用 python set 去重 速度到底是多快呢???
  6. RF元素定位的例子
  7. 宝塔https部署没成功的原因排查
  8. 套接字编程(TCP)
  9. LRU Algorithm Gym - 102394L (HASH)
  10. sql语句练习50题(Mysql版) 围观