一.在spring配置文件中引用对应的定时任务配置文件
二.定义定时任务的业务代码
三.配置定时任务配置文件spring-quartz.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--增加线程池-->
<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="100" />
<property name="queueCapacity" value="500" />
</bean>
<!--定义业务逻辑类-->
<bean id = "bizObject" class="com.XXXX.XXX.XXXX.XXXX.service.demo.DemoServiceImpl"/>
<!-- 增加调度业务 -->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="bizObject" />
<property name="targetMethod" value="saveDemo" />
</bean>
<!--执行调度-->
<bean id = "ceshiTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail"/>
<property name="cronExpression" value="10 0/1 * * * ?"/>
</bean>
<!-- 启动调度 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="ceshiTrigger" />
</list>
</property>
<property name="taskExecutor" ref="executor" />
</bean>
</beans>