用注解方式写定时任务

spring里加上

</context:component-scan>
<!-- 任务自动扫描 -->
<task:annotation-driven/>
<!-- 扫描位置 -->
<context:annotation-config/>  
    <context:component-scan base-package="com.xxx.xxx"/>

然后在类上面添加注解  @Component,声明他是一个组件

时间: 2024-08-26 09:44:27

用注解方式写定时任务的相关文章

Spring通过注解方式实现定时任务

XML配置: 1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springfr

「spring」定时任务(纯注解方式)

[问题现象] 需要通过纯注解方式启动定时任务,网上搜索到的定时任务大部分都是配置+注解. [问题解决] /** * 定时任务:打印CPU使用率 */@Component@EnableSchedulingpublic class PrintCpuWorker {    @Scheduled(cron="0/10 * *  * * ? ") // 每10秒一次    public void print() {        System.out.println("PrintCpu

springmvc2 一个控制器写多个方法(非注解方式)

出处:http://blog.csdn.net/xuewenke/article/details/23895999 springmvc2 一个控制器写多个方法(非注解方式) 分类: spring 2014-04-17 02:50 318人阅读 评论(0) 收藏 举报 web.xml 的配置. 其实web.xml 的配置和之前的没有什么区别  主要是DispatcherServlet 的配置,他是springvc的核心,是前端拦截器,主要负责拦截请求,然后在分派.这次配置时 springmvc的配

纯手写SpringBoot框架之注解方式启动SpringMVC容器

使用Java语言创建Tomcat容器,并且通过Tomcat执行Servlet,接下来,将会使用Java语言在SpringBoot创建内置Tomcat,使用注解方式启动SpringMVC容器. 代码实现.1.pom.xml文件,需要依赖的jar包. <dependencies> <!--Java语言操作Tomcat--> <dependency> <groupId>org.apache.tomcat.embed</groupId> <arti

【Quartz】基于Spring注解方式配置Quartz

林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka         在上讲[Quartz]Spring3.2.9+Quqrtz2.2.1实现定时实例中,我们使用了XML的方式来配置Quartz定时任务,虽然比用API的方式简便多了,但是Spring还支持基本注解的方式来配置.这样做不仅更加简单,而且代码量也更加少了. 新建一个Java工程,导入要用到的包,Spring3.2.Quartz2.2.1.aopalliance-1.0.jar.co

注解方式实现声明式事务管理

使用注解实现Spring的声明式事务管理,更加简单! 步骤: 1) 必须引入Aop相关的jar文件 2) bean.xml中指定注解方式实现声明式事务管理以及应用的事务管理器类 3)在需要添加事务控制的地方,写上: @Transactional @Transactional注解: 1)应用事务的注解 2)定义到方法上: 当前方法应用spring的声明式事务 3)定义到类上:   当前类的所有的方法都应用Spring声明式事务管理; 4)定义到父类上: 当执行父类的方法时候应用事务. 修改bean

Spring之AOP基本概念及通过注解方式配置AOP

为什么使用AOP 传统方法 AOP前前奏 首先考虑一个问题,假设我们要设计一个计算器,有如下两个需求: - 在程序运行期间追踪正在放生的活动 - 希望计算器只能处理正数的运算 通常我们会用如下代码进行实现: 定义一个接口: public interface ArithmeticCalculator { int add(int i, int j); int sub(int i, int j); int mul(int i, int j); int div(int i, int j); } 实现类(

spring注解方式实现DI和IOC

注解复习: 1.注解就是为了说明java中的某一个部分的作用(Type) 2.注解都可以用于哪个部门是@Target注解起的作用 3.注解可以标注在ElementType枚举类所指定的位置上 4. 元注解 @Documented    //该注解是否出现在帮助文档中 @Retention(RetentionPolicy.RUNTIME) //该注解在java,class和运行时都起作用 @Target(ElementType.ANNOTATION_TYPE)//该注解只能用于注解上 public

Spring 使用注解方式进行事务管理

使用步骤: 步骤一.在spring配置文件中引入<tx:>命名空间<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation