问题描述
- 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" />
解决方案
解决方案二:
xml文件里面没有配置task吧