Spring 定时任务执行两次 解决办法

先说原因,看到同一个任务执行两次,而且是并行执行,同一时间点执行的代码输出一样,网上查了资料,原因是因为下面两段代码

<init-param>
      <description>spring mvc 配置文件</description>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-mvc.xml</param-value>
 </init-param>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-*.xml</param-value>
  </context-param>

SpringMVC中再web.xml中有上面两行代码片,我的定时器配置在spring-mvc.xml,在项目启动的时候扫描了两遍配置文件,也就是两个容器中都拿到了定时器。

解决方法:单独把定时器配置文件new出来一个spring-quarz.xml,然后就可以了,其他博客说修改tomcat中的配置文件,把appBase=’webapps’ 设置为appBase=”,反正我试过没用。


版权声明:本文为sinat_21946155原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。