用 Maven 构建的 Spring 3.2.3,尝试使用 @Scheduled 做定时任务,没有生效,但也未报任何错误。
环境:
pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
com.test
xyz
war
0.0.1-SNAPSHOT
xyz
http://maven.apache.org
org.springframework
spring-core
3.2.3.RELEASE
org.springframework
spring-beans
3.2.3.RELEASE
org.springframework
spring-context
3.2.3.RELEASE
org.springframework
spring-aop
3.2.3.RELEASE
org.springframework
spring-aspects
3.2.3.RELEASE
org.springframework
spring-web
3.2.3.RELEASE
log4j
log4j
1.2.17
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
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-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd"
default-autowire="byName" default-lazy-init="true">
<context:component-scan base-package="com.test" />
<task:annotation-driven />
测试任务
package com.test.task;
import java.util.Date;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class MyTask {
@Scheduled(cron = "0/5 * * * * ?")
public void doSth() {
System.out.println(new Date());
}
}
但是,如果不使用 @Scheduled,用 标签则任务正常运行:
task:scheduled-tasks
/task:scheduled-tasks
求解?