springboot系列之使用spring quartz (xml方式)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_17522211/article/details/84580826

需要说明: springboot并不建议使用xml进行配置,但是由于特殊原因,也会存在xml的配置信息.
如上一篇所讲springquartz月末执行配置L不支持注解.故需使用配置文件进行配置.
PS: 会持续更新springboot系列,希望大家多多支持. >_<

maven: 还是和上一篇一样

<dependency>
	<groupId>org.quartz-scheduler</groupId>
	<artifactId>quartz</artifactId>
	<version>2.2.1</version>
	<exclusions>
		<exclusion>
			<artifactId>slf4j-api</artifactId>
			<groupId>org.slf4j</groupId>
		</exclusion>
	</exclusions>
</dependency>
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-context-support</artifactId>
</dependency>

applicationContext-quartz.xml

<?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
	// 定时任务类
	<bean id="rdpCsCbjtTask" class="com.xxx.xxx.Task"></bean>
	<bean id="stopDealTask" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
		<property name="targetObject">
			<ref bean="rdpCsCbjtTask" />
		</property>
		<property name="targetMethod">
			// 方法名称
			<value>stopDeal</value>
		</property>
	</bean>
	<bean id="doStopDeal" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
		<property name="jobDetail">
			<ref bean="stopDealTask" />
		</property>
		<property name="cronExpression">
			// 每月最后一天 23:50执行
			<value>0 50 23 L * ?</value>
		</property>
	</bean>
	
	<bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
		<property name="triggers">
			<list>
				<ref bean="doStopDeal" />
			</list>
		</property>
	</bean>
</beans>

springboot引入xml配置:

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
/**
 * 引入外部资源
 */
@Configuration
@ImportResource(locations={"classpath:applicationContext-quartz.xml"})
public class XMLSource {
}

猜你喜欢

转载自blog.csdn.net/qq_17522211/article/details/84580826