spring结合定时任务
pom.xml
<!-- spring额外集成邮件,任务调度,邮件模版 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<!-- 任务调度(定时任务) -->
<dependency>
<groupId>quartz</groupId>
<artifactId>quartz</artifactId>
<version>1.5.2</version>
</dependency>
applicationxontext-qz
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- cron表达式:在每天早上8点到晚上8点期间每1分钟触发一次 -->
<!--value>0 0/1 8-20 * * ?</value -->
<!-- cron表达式:每5分钟触发一次 -->
<!-- <value>0 0/5 * * * ?</value> -->
<task:scheduled-tasks>
<!-- 执行quartzJob里面的work方法,执行频率是cron表达式 -->
<task:scheduled ref="quartzJob" method="work" cron="0 0/1 * * * ?" />
</task:scheduled-tasks>
</beans>
//定时执行的类容
@Service("QzJob")
public class QuartzJobServiceImpl implements IQuartzJobService {
@Override
public void work() {
System.out.println("---------------------------------"
}