shuzheng 9 жил өмнө
parent
commit
c689cf3efb

+ 8 - 0
cms/cms-web/src/main/java/com/zheng/cms/task/TestTask.java

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

+ 19 - 0
cms/cms-web/src/main/java/com/zheng/cms/task/impl/TestTaskImpl.java

@@ -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");
+	}
+
+}

+ 8 - 1
common/src/main/resources/applicationContext.xml

@@ -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>