使用spring的@Scheduled注解执行定时任务,启动项目不输出警告

在applicationContext.xml中添加:

xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-4.0.xsd">

<task:annotation-driven executor="myExecutor" scheduler="myScheduler" />
<task:executor id="myExecutor" pool-size="5" />
<task:scheduler id="myScheduler" pool-size="10" />

java代码:

@Component
public class CleanExpireTokenTask {

    private Logger logger = LoggerFactory.getLogger(LogTag.BUSINESS);

    @Scheduled(cron = "0 * * * * ?")
    public void startUpdateSaleThread(){
        try{
            System.out.println("check token expire");
        }catch(Exception e){
            logger.error("Make salesReport faild",e);
        }
    }
}

注意:

实现类上要加注解@Component

定时器的任务方法不能有返回值

配置及启动报错问题参考自

http://stackoverflow.com/questions/30431776/using-scheduled-and-enablescheduling-but-gives-nosuchbeandefinitionexception

http://www.cnblogs.com/luwinner/p/5109327.html

时间: 2024-08-25 12:18:25

使用spring的@Scheduled注解执行定时任务,启动项目不输出警告的相关文章

Spring 的@Scheduled注解实现定时任务执行和调度

首先要配置我们的spring.xml   ---  即spring的主配置文件(有的项目中叫做applicationContext.xml或context.xml) xmlns 多加下面的内容. [html] view plaincopy xmlns:task="http://www.springframework.org/schema/task" 然后xsi:schemaLocation多加下面的内容. [html] view plaincopy http://www.springf

使用spring @Scheduled注解执行定时任务

首先要配置我们的spring.xml xmlns 多加下面的内容 1 xmlns:task="http://www.springframework.org/schema/task" 然后xsi:schemaLocation多加下面的内容 1 http://www.springframework.org/schema/task 2 http://www.springframework.org/schema/task/spring-task-3.1.xsd 最后是我们的task任务扫描注解

spring @Scheduled注解执行定时任务

以前框架使用quartz框架执行定时调度问题. 这配置太麻烦.每个调度都需要多加在spring的配置中. 能不能减少配置的量从而提高开发效率. 最近看了看spring的 scheduled的使用注解的方式进行调度. 感觉很方便.起码配置的东西少了很多. 所以留下来以备忘了. 首先要配置我们的spring.xml xmlns 多加下面的内容. [html] view plain copy xmlns:task="http://www.springframework.org/schema/task&

使用spring @Scheduled注解执行定时任务、

以前框架使用quartz框架执行定时调度问题. 老大说这配置太麻烦.每个调度都需要多加在spring的配置中. 能不能减少配置的量从而提高开发效率. 最近看了看spring的 scheduled的使用注解的方式进行调度. 感觉很方便.起码配置的东西少了很多. 所以留下来以备忘了. 首先要配置我们的spring.xml xmlns 多加下面的内容. [html] view plaincopyprint? xmlns:task="http://www.springframework.org/sche

【转】使用spring @Scheduled注解执行定时任务

http://blog.csdn.net/sd4000784/article/details/7745947 以前框架使用quartz框架执行定时调度问题. 老大说这配置太麻烦.每个调度都需要多加在spring的配置中. 能不能减少配置的量从而提高开发效率. 最近看了看spring的 scheduled的使用注解的方式进行调度. 感觉很方便.起码配置的东西少了很多. 所以留下来以备忘了. 首先要配置我们的spring.xml xmlns 多加下面的内容. [html] view plain co

Spring 的@Scheduled注解实现定时任务运行和调度

首先要配置我们的spring.xml   ---  即spring的主配置文件(有的项目中叫做applicationContext.xml或context.xml) xmlns 多加以下的内容. [html] view plaincopy xmlns:task="http://www.springframework.org/schema/task" 然后xsi:schemaLocation多加以下的内容. [html] view plaincopy http://www.springf

使用轻量级Spring @Scheduled注解执行定时任务

WEB项目中需要加入一个定时执行任务,可以使用Quartz来实现,由于项目就一个定时任务,所以想简单点,不用去配置那些Quartz的配置文件,所以就采用了Spring @Scheduled注解来实现了定时任务.在这里做个备注. spring配置文件  xmlns中加入一段: xmlns:task="http://www.springframework.org/schema/task" 然后xsi:schemaLocation多加下面的内容: http://www.springframe

使用spring @Scheduled注解运行定时任务、

曾经框架使用quartz框架运行定时调度问题. 老大说这配置太麻烦.每一个调度都须要多加在spring的配置中. 能不能降低配置的量从而提高开发效率. 近期看了看spring的 scheduled的使用注解的方式进行调度. 感觉非常方便.起码配置的东西少了非常多. 所以留下来以备忘了. 首先要配置我们的spring.xml xmlns 多加以下的内容. xmlns:task="http://www.springframework.org/schema/task" 然后xsi:schem

SpringMVC框架使用注解执行定时任务

在项目开发过程中,免不了会有一些定时任务.今天就给大家一个SpringMVC框架中利用注解的方式执行定时任务的示例代码 使用到的JAR文件: 点击下列Jar文件会跳到我的网盘下载 aopalliance-1.0.jarcommons-logging-1.1.3.jarspring-aop-3.2.4.RELEASE.jarspring-beans-3.2.4.RELEASE.jarspring-context-3.2.4.RELEASE.jarspring-core-3.2.4.RELEASE.