Spring通过注解方式实现定时任务
XML配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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 ">
<!-- 扫描包基础目录 -->
<context:component-scan base-package="com.wisezone" />
<!-- 识别@Scheduled注解 -->
<task:annotation-driven/> </beans>
java代码:
package com.wisezone.service; import java.text.SimpleDateFormat;
import java.util.Date; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; @Service
public class JobService { @Scheduled(cron="0/2 * * * * ?")
public void job(){
System.out.println("定时输出任务:"+new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
}
}
测试类:
package com.wisezone.test; import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Test
{
public static void main(String[] args)
{
ApplicationContext app = new ClassPathXmlApplicationContext("beans.xml"); }
}
结果:
Spring通过注解方式实现定时任务的更多相关文章
- mybatis源码学习--spring+mybatis注解方式为什么mybatis的dao接口不需要实现类
相信大家在刚开始学习mybatis注解方式,或者spring+mybatis注解方式的时候,一定会有一个疑问,为什么mybatis的dao接口只需要一个接口,不需要实现类,就可以正常使用,笔者最开始的 ...
- (转)使用Spring的注解方式实现AOP的细节
http://blog.csdn.net/yerenyuan_pku/article/details/52879669 前面我们已经入门使用Spring的注解方式实现AOP了,现在我们再来学习使用Sp ...
- (转)使用Spring的注解方式实现AOP入门
http://blog.csdn.net/yerenyuan_pku/article/details/52865330 首先在Eclipse中新建一个普通的Java Project,名称为spring ...
- spring boot注解之@Scheduled定时任务实现
java实现定时任务一般使用timer,或者使用quartz组件.现在在spring boot提供了更加方便的实现方式. spring boot已经集成了定时任务.使用@Secheduled注解. @ ...
- spring aop注解方式与xml方式配置
注解方式 applicationContext.xml 加入下面配置 <!--Spring Aop 启用自动代理注解 --> <aop:aspectj-autoproxy proxy ...
- Spring的注解方式实现AOP
Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...
- 使用Spring的注解方式实现AOP
Spring对AOP的实现提供了很好的支持.下面我们就使用Spring的注解来完成AOP做一个例子. 首先,为了使用Spring的AOP注解功能,必须导入如下几个包.aspectjrt.jar,asp ...
- Spring的注解方式
在Java代码中可以使用@Resource或者@Autowired注解方式来经行注入.虽然@Resource和@Autowired都可以来完成注入依赖,但它们之间是有区别的. a.@Resource默 ...
- Spring 使用注解方式进行事务管理
转载:http://www.cnblogs.com/younggun/archive/2013/07/16/3193800.html 使用步骤: 步骤一.在spring配置文件中引入<tx:&g ...
随机推荐
- HDU 3199 Hamming Problem
Hamming Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- 【转】SVN使用教程总结
看到一篇超赞的文章,原链接:http://www.cnblogs.com/armyfai/p/3985660.html SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成 ...
- loadrunder之脚本篇——定义全局变量
如果参数是全局的,在脚本中的任何一个Action中都可以使用,变量一般是局部的,如果跨Action调用会出现未声明的错误. 打开Script视图中左侧Action列表中的globals.h文件,可定义 ...
- 函数---迭代器&生成器&列表解析&三元表达式
可迭代对象:obj.__iter__ 迭代器:iter1=obj.__iter() 1iter1.__next__ 2iter2.__next__ 迭代器: 优点:不依赖索引 ...
- vmxnet3 丢包处理
https://vswitchzero.com/2017/09/26/vmxnet3-rx-ring-buffer-exhaustion-and-packet-loss/
- Oracle、Mysql、SqlServer创建表和给表和字段加注释
一.Oracle --创建表 create table test ( id varchar2(200) primary key not null, sort number, ...
- maven 一个简单项目 —— maven权威指南学习笔记(三)
目标: 对构建生命周期 (build lifecycle),Maven仓库 (repositories),依赖管理 (dependency management)和项目对象模型 (Project O ...
- java.lang.NullPointerException报错的几种情况
java.lang.NullPointerException报错的几种情况: 1.字符串变量未初始化: 2.接口类型的对象没有用具体的类初始化,比如: List stuList :这种情况就会报空指针 ...
- delphi中httpencode使用注意事项
delphi中httpencode使用注意事项 一.uses HTTPApp二.使用前要用UTF8Encode转换成utf-8编码HTTPEncode(UTF8Encode(Text));不然和标准的 ...
- hdoj1006--Tick and Tick
Problem Description The three hands of the clock are rotating every second and meeting each other ma ...