启动任务注解

This commit is contained in:
shuzheng 2016-11-01 10:19:08 +08:00
parent a3b984f73d
commit c689cf3efb
3 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,8 @@
package com.zheng.cms.task;
/**
* Created by ZhangShuzheng on 2016/11/1.
*/
public interface TestTask {
public void test();
}

View File

@ -0,0 +1,19 @@
package com.zheng.cms.task.impl;
import com.zheng.cms.task.TestTask;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Created by ZhangShuzheng on 2016/11/1.
*/
@Component
public class TestTaskImpl implements TestTask {
@Scheduled(cron = "0 0/1 * * * ?")
@Override
public void test() {
System.out.println("Task");
}
}

View File

@ -2,11 +2,14 @@
<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: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/context/spring-context.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task.xsd">
<!-- 装载service -->
<context:component-scan base-package="**.service" />
@ -14,4 +17,8 @@
<!-- 启动时初始化Spring上下文环境工具类 -->
<bean id="springContextUtil" class="com.zheng.common.util.SpringContextUtil"></bean>
<!-- 启动任务注解 -->
<task:annotation-driven />
<context:component-scan base-package="**.task" />
</beans>