weixin_42505690 2013-07-01 18:58
浏览 2395
已采纳

Spring 3.2.3 使用 @Scheduled 注解的定时任务没有生效

用 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

求解?

  • 写回答

2条回答 默认 最新

  • jinnianshilongnian 2013-07-01 20:44
    关注

    怀疑 default-lazy-init="true" 惹得祸

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧