spring 定时器 @Component 执行两次 问题解决

来源:互联网 发布:网络分布式继电器接线 编辑:程序博客网 时间:2024/06/04 18:25

我的问题原因 是 因为我的定时器配置在SpringMVC的配置文件applicationContext.xml中,而web.xml中ContextLoaderListener 和 DispatcherServlet都会扫描这个文件。故而项目启动时定时器会执行两次。

所以 只需要将 定时器配置单独 配成一个文件 applicationContext-task.xml,



ContextLoaderListener 中加入扫描这个文件即可。



之前百度的其他答案 把appBase="webapps" 设置为appBase=""  对我的问题没用。


原创粉丝点击