springboot实现:
/**
* ,每分钟执行一次
*/
@Scheduled(cron = "0 * * * * ?")
protected void getSomeThring2 (){
System.out.println("每分钟执行一次ScheduleDamo.getSomeThring2");
log.info("每分钟执行一次ScheduleDamo.getSomeThring2");
}
spring实现:与springboot一样的java代码 只是多出了以下配置:
需要在bean标签中引入以下参数:
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">以及以下配置:
<task:annotation-driven scheduler="taskScheduler"/> <task:scheduler id="taskScheduler" pool-size="5"/>案例如下:
<?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: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/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">
<task:annotation-driven scheduler="taskScheduler"/>
<task:scheduler id="taskScheduler" pool-size="5"/>
</beans>