maven构建使用Spring执行定时任务
首先,pom.xml中加入依赖:
版本配置信息:
依赖:
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: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">
相关阅读: