一、配置文件中要有如下代码
<beans xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<bean id="expire" class="com.sitech.cmap.schedule.expired.ExpiredJobImpl">
</bean>
<!-- 每天0点调度 cron="0 0 0 * * ?" -->
<task:scheduled-tasks>
<task:scheduled ref="expire" method="accountExpiredJob" cron="0 0 0 * * ?"/>
</task:scheduled-tasks>
<!-- 每天1点调度 cron="0 0 1 * * ?" -->
<task:scheduled-tasks>
<task:scheduled ref="expire" method="passwordExpiredJob" cron="0 0 1 * * ?"/>
</task:scheduled-tasks>
<context:component-scan base-package="com.sitech.cmap" />
</beans>
二、具体调度类如下
package com.sitech.cmap.schedule.expired;
public class ExpiredJobImpl {
public void accountExpiredJob(){
System.out.println(DateUtil.dateToString(new Date()) + "账号过期调度进行中。。。");
//想要写的代码
}
public void passwordExpiredJob() {
System.out.println(DateUtil.dateToString(new Date()) + "密码过期调度进行中。。。");
//想要写的代码
}
}