引入 ServletContextListener @Autowired null 解决办法
2024-09-03 13:14:47
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还没有加载,所以会出现问题。
最新文章
- visual stdio 2015安装配置及原理
- windows下打包react-native应用程序
- iOS播放铃声及震动,适用于扫描、新消息等
- BZOJ-1880 Elaxia的路线 SPFA+枚举
- juery动态添加和删除
- Linux下查看用户列表
- ubuntu 修改ssh远程主机名称,mac开机运行命令,静默方式启动virtual box虚拟机,静默执行run脚本
- php生成代金券码
- netcore程序部署到docker
- autpmapper映射忽略某个属性
- Python3 Tcp未发送/接收完数据即被RST处理办法
- VMware与Centos系统安装、重置root密码
- ubuntu15.04中安装mysql和mysql-workbench
- python3_unittest单元测试框架
- node制作代理服务器
- Google Breakpad 完全解析(二) —— Windows前台实现篇
- list!=null跟list.isEmpty()有什么区别?
- gym - 101673I Twenty Four, Again (表达式树枚举)
- Bicoloring UVA - 10004 二分图判断
- 获取Android设备无线和以太网MAC地址
热门文章
- 160--Intersection Of Two Linked List
- Nios II IDE代码优化,quartus ii 11.0版本IDE
- springboot easypoi 报错The bean 'beanNameViewResolver', defined in class path resource [cn/afterturn/e
- Codeforces H. Kilani and the Game(多源BFS)
- 使用 python set 去重 速度到底是多快呢???
- RF元素定位的例子
- 宝塔https部署没成功的原因排查
- 套接字编程(TCP)
- LRU Algorithm Gym - 102394L (HASH)
- sql语句练习50题(Mysql版) 围观