maven构建使用Spring执行定时任务
首先,pom.xml中加入依赖:
版本配置信息:
1.6
3.1.1.RELEASE
2.2.1
1.6.10
1.6.6
依赖:
org.springframework
spring-context
${org.springframework-version}
commons-logging
commons-logging
commons-beanutils
commons-beanutils
commons-digester
commons-digester
org.springframework
spring-context-support
${org.springframework-version}
org.springframework
spring-tx
${org.springframework-version}
org.springframework
spring-web
${org.springframework-version}
org.quartz-scheduler
quartz
1.8.5
org.springframework
spring-webmvc
${org.springframework-version}
org.aspectj
aspectjrt
${org.aspectj-version}
java代码:
package com.cetc.yun.service.impl;
import org.apache.log4j.Logger;
import com.cetc.yun.service.TaskTestService;
public class TaskTestServiceImpl implements TaskTestService {
private static Logger log = Logger.getLogger(TaskTestServiceImpl.class);
@Override
public void sayHello() {
// TODO Auto-generated method stub
try {
log.info("处理任务开始>........");
// 业务逻辑代码调用
log.info("时间[" + new java.util.Date().toGMTString()
+ "]----->大家好啊!");
log.info("处理任务结束!");
} catch (Exception e) {
log.error("处理任务出现异常", e);
}
}
}
关键配置信息:
< xml version="1.0" encoding="UTF-8" >
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http://www.springframework.org/schema/task"
xmlns:beans="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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/task
http://www.springframework.org/schema/task/spring-task-3.1.xsd">
sayHello
0/5 * 08-21 * *
相关阅读: