- 确认不是因为代码导致的重复执行定时任务:
debug源码,看定时任务触发时是否重复进入源码。 - 解决方案一
将spring中mvc的xml文件和其他的xml文件进行分离;
例如:`
第一部分:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/cis-website-webapp-${mode}.properties</value>
</list>
</property>
</bean>
<!-- 导入配置 -->
<import resource="classpath:spring-repository.xml" />
<import resource="classpath:spring-investment-service.xml" />
<import resource="classpath:spring-lend-service.xml" />
<import resource="classpath:spring-user-service.xml" />
<import resource="classpath:spring-webservice.xml" />
<import resource="classpath:spring-product-service.xml" />
<import resource="classpath:spring-activemq-consumer.xml" />
第二部分:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/cis-website-webapp-${mode}.properties</value>
</list>
</property>
</bean>
<!-- 注解驱动 -->
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
<bean class="org.springframework.http.converter.FormHttpMessageConverter" />
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter" />
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 组件扫描 -->
<context:component-scan base-package="com.zhb.cis.website.controller" />
<!-- 视图分析 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<!-- <mvc:view-controller path="/" view-name="login" /> <mvc:view-controller
path="/redirect" view-name="redirect" /> -->
<mvc:view-controller path="/index" view-name="index" />
<!-- 资源相关 -->
<mvc:resources location="/WEB-INF/css/" mapping="/css/**" />
<mvc:resources location="/WEB-INF/views/" mapping="/views/**" />
<mvc:resources location="/WEB-INF/js/" mapping="/js/**" />
<mvc:resources location="/WEB-INF/images/" mapping="/images/**" />
<mvc:resources location="/WEB-INF/plugin/" mapping="/plugin/**" />
<mvc:resources location="/WEB-INF/template/" mapping="/template/**" />
<!-- 拦截器 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/webservice/rest/**" />
<bean class="com.zhb.cis.website.interceptor.HttpRequestValidator"></bean>
</mvc:interceptor>
</mvc:interceptors>
<import resource="classpath:spring-quartz.xml"/>`
将第一部分和第二部分分离,第一部分配置在web.xml中context-param标签内,第二部分配置在web.xml中servlet的init-param标签内。
归根到底,其实就是重复加载了定时任务的配置文件。
-
解决方案二
删除或注释掉Tomcat中server.xml中的<Context docBase="work/DataInput_2017" path="" reloadable="false"/>
,注意这个标签是在Host标签内的。问题已经完美解决。