第一步
检查配置文件,文件内有配置concurrent为false,理论上来讲应该可以防止job同时执行两次的问题。
[
html]
< xml version="1.0" encoding="UTF-8" >
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
第二步
既然不是quartz配置的问题,那就往上一层代码找找看吧,忽然发现SSH项目中出现了ApplicationContext被连续两次注入的问题,但是我只是在web.xml进行了一次引用配置,不应该调用两次才对...
[html]
在applicationContext.xml中
[html]
第三步
虽然不知道什么造成多次注入的问题,但总归知道是什么造成的了,从网上查一下吧 applicationContext.xml多次注入,从网上得来原因,一般的说法是:
在web.xml进行配置applicationConetxt.xml的引用会似使得注入一次,同时spring自己进行加载该文件会使得注入一次。因此造成了两次注入;
既然如此,那我就把quartz的配置提取出来不就可以了,然后我就把quartz的配置写入到了job.xml中,然后更改web.xml文件如下 :
[html]
理论上来讲应该没问题了吧,但是还是不可以,applicationContext加载两次可以说得过去,但是定时任务还是被同时执行了两次,因此我得出了结果,不是applicationContext.xml被加载了两次,而是web.xml被加载了两次,从而造成了以上的结果。
那我就去查,什么情况下会出现web.xml被多次加载?
原来是TOMCAT的配置文件server.xml配置不当引起的
请看下面这段配置就是错误的:
[html]
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
tomcat的默认加载工程目录为tomcat\webapps\....,这就会造成加载一次Server项目下的web.xml 第一次注入
由于本地中的工程有很多,所以为了方便配置了默认启动项目,添加了上面蓝色的配置,造成了第二次注入
解决办法:
1.更改server.xml中appBase=""。再次启动项目,一切正常。
2.删除蓝色配置,将项目放到tomcat\webapps\ROOT中,以此来达到默认启动的效果。
暂时只发现这两种解决办法,如果大家还有什么其他的解决办法,欢迎留言