Spring的MethodInvokingJobDetailFactoryBean定时任务重复执行问题解决方案

  1. 确认不是因为代码导致的重复执行定时任务:
    debug源码,看定时任务触发时是否重复进入源码。
  2. 解决方案一
    将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标签内。
归根到底,其实就是重复加载了定时任务的配置文件。
  1. 解决方案二
    删除或注释掉Tomcat中server.xml中的<Context docBase="work/DataInput_2017" path="" reloadable="false"/>,注意这个标签是在Host标签内的。

    问题已经完美解决。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值