2 mwyking mwyking 于 2016.04.05 19:25 提问

SPRING @Scheduled 定时任没执行

项目主要配置及代码如下,但是启动服务后,一直没执行这个方法,不知什么原因。请指点

package com.yl.reqPos;

import java.text.SimpleDateFormat;

import java.util.Date;

import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;

import org.springframework.stereotype.Component;
@Component
@Lazy(false)
public class Singer {

@Scheduled(cron  ="0/5 * * * * *")     //第二种方式  
    public void singing(){  
    Date date=new Date();  
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
    System.out.println(sdf.format(date));  
}  

}

applicationContext-jobs.xml配置:
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-lazy-init="false">

<context:component-scan base-package="com.yl.reqPos.*" />



queue-capacity="500" rejection-policy="CALLER_RUNS" />

2个回答

CSDNXIAON
CSDNXIAON   2016.04.05 19:32

spring----@Scheduled注解执行定时任务
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

liuy_88
liuy_88   2016.04.07 12:27

xml文件里面没有配置task吧

Csdn user default icon
上传中...
上传图片
插入图片