spring 基于task机制调用(使用注解)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cuisongliu/article/details/49359359
  • xml配置
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/task 
    http://www.springframework.org/schema/task/spring-task-3.0.xsd">

<!--

这里加入了
xmlns:task="http://www.springframework.org/schema/task"
http://www.springframework.org/schema/task 
    http://www.springframework.org/schema/task/spring-task-3.0.xsd

-->

<!-- 开启这个配置,spring才能识别@Scheduled注解    -->  
    <task:annotation-driven scheduler="qbScheduler" mode="proxy"/>  
    <task:scheduler id="qbScheduler" pool-size="10"/>
</beans>
  • 注解使用
@Component("jobService")
@Lazy(false)
public class JobService{
    @Autowired
    private CwsDayChangeService cwsDayChangeService;

    @Autowired
    private SysLogService sysLogService;

    //@Scheduled(cron = "0 0 23 * * ?")  
    public void dayJob() throws Exception {  
        try {
            //do something ....
        } catch (Exception e) {

            throw e;
        }
    }
}
阅读更多

没有更多推荐了,返回首页