spring3.0定时器 xml配置和注解方式
2016-08-28 14:09
232 查看
1.xml配置方式
web.xml
[code=xml;toolbar:false"><!-- 配置spring监听器和配置文件路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>spring配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
<task:scheduled-tasks>
<task:scheduled ref="taskJob" method="job1" cron="0 * * * * ?"/>
</task:scheduled-tasks>
<context:component-scan base-package="com.gy.mytask" />这里定时每分钟的的零秒开始执行cron="0 * * * * ?"java类,方法无返回值package com.gy.mytask;
import org.springframework.stereotype.Service;
@Service
public class TaskJob {
public void job1() {
System.out.println("任务进行中。。。");
System.out.println(Thread.currentThread().getName());
}
}
[b]
web.xml
[code=xml;toolbar:false"><!-- 配置spring监听器和配置文件路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>spring配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"
<task:scheduled-tasks>
<task:scheduled ref="taskJob" method="job1" cron="0 * * * * ?"/>
</task:scheduled-tasks>
<context:component-scan base-package="com.gy.mytask" />这里定时每分钟的的零秒开始执行cron="0 * * * * ?"java类,方法无返回值package com.gy.mytask;
import org.springframework.stereotype.Service;
@Service
public class TaskJob {
public void job1() {
System.out.println("任务进行中。。。");
System.out.println(Thread.currentThread().getName());
}
}
[b]
相关文章推荐
- spring3.0定时器 xml配置和注解方式
- Spring定时器的配置(注解+xml)方式
- Spring 配置定时器(注解+xml)方式—整理
- Spring 配置定时器(注解+xml)方式—整理
- 实例说明Spring实现AOP的2种方式(注解和XML配置)
- Hibernate 实体映射 @注解与xml 配置方式比较
- Spring的XML配置的bean调用注解方式的bean
- Spring 管理hibernate事物,xml配置,注解 两种实现方式
- spring aop的使用(注解方式以及基于xml配置方式)
- SSH深度历险(十一) AOP原理及相关概念学习+xml配置实例(对比注解方式的优缺点)
- Spring定时器技术终结者——采用XML配置的方式实现Spring定时器
- spring+hibernate xml和注解方式配置事务
- spring aop的使用(注解方式以及基于xml配置方式)
- Hibernate 注解时 hibernate.hbm.xml的配置方法 以及与SSH整合里的配置方式
- Spring学习一:IOC(控制反转)和AOP(面向切面)的xml配置和注解方式
- Spring 3.0.5 MVC 基于注解ehcache.xml 配置方式
- SSH框架下,用Annotations注解方式替代hbm.xml配置文件
- spring aop的使用(注解方式以及基于xml配置方式)
- 如何用注解方式配置定时器squartz
- spring之aop编程——基于注解、xml配置文件方式