spring3.1的BeanFactory与Quartz1.8整合
spring的applicationContext.xml配置文件:
加入
<bean id="myJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.job.Service</value>
</property>
</bean>
<bean id="myCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="myJob"/>
</property>
<property name="cronExpression">
<value>0 0 1 * * ?</value>
</property>
</bean>
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobFactory">
<bean class="com.JobFactory"/>
</property>
<property name="triggers">
<list>
<ref bean="myCronTrigger"/>
</list>
</property>
</bean>
quartz与spring的BeanFactory整合的类:
/**
* 为定时器提供自动注入功能
*/
public class JobFactory extends SpringBeanJobFactory implements
ApplicationContextAware { private ApplicationContext applicationContext; @Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
} @Override
protected Object createJobInstance(TriggerFiredBundle bundle)
throws Exception {
Object jobInstance = super.createJobInstance(bundle);
applicationContext.getAutowireCapableBeanFactory().autowireBean( jobInstance);
return jobInstance;
} }
定时任务类:
public class MyService extends QuartzJobBean {
private static final Log log = LogFactory.getLog(MyService.class);
@Resource
private UserService userService;
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext)
throws JobExecutionException {
log.info("执行定时任务");
userService.freshUserAmount();
}
}
Quartz中时间表达式的设置-----corn表达式
时间格式: <!-- s m h d m w(?) y(?) -->, 分别对应: 秒>分>小时>日>月>周>年,
spring3.1的BeanFactory与Quartz1.8整合的更多相关文章
- Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码)
Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码) 备注: 之前在Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合中 ...
- Spring3.1.2与Hibernate4.1.8整合
整合Spring3.1.2 与 Hibernate 4.1.8 首先准备整合jar: Spring3.1.2: org.springframework.aop-3.1.2.RELEASE.jar or ...
- spring3.0的BeanFactory上下文context获取不到bean
开门见山,背景: 系统初始化的时候扫包实例化bean,然后一个工具类实现ServletContextAware接口,拿到servletContext之后: WebApplicationContextU ...
- spring3.2.0与mybatis3.2.7整合出错--Failed to read candidate component class--nested exception is java.lang.IllegalArgumentException
错误信息如下: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate com ...
- Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合
项目环境背景: 操作系统:win7 JDK:1.7 相关依赖包,截图如下:
- Spring3.2.11与Quartz2.2.1整合时内存泄漏的问题的解决
Quartz是一款定时任务调度的开源框架,使用起来比较方便.并且Spring的support包对Quartz有集成.但是笔者在web应用使用的过程中却遇到了内存泄漏的问题. 问题的产生 笔者在使用Sp ...
- Maven 整合 spring profile实现多环境自动切换
Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...
- mybatis0211 mybatis和spring整合
1mybatis和spring整合 1.1 mybaits和spring整合的思路 .让spring管理SqlSessionFactory .让spring管理mapper动态代理对象和dao. 使用 ...
- [转]基于全注解的Spring3.1 mvc、myBatis3.1、Mysql的轻量级项目
摘要 对于现在主流的j2ee企业级开发而言,ssh(struts+hibernate+spring)依然是一个事实的标准.由struts充当的mvc调度控制:hibernate的orm持久化映射:sp ...
随机推荐
- Oracle 存储过程(2)
http://www.cnblogs.com/chinafine/archive/2010/07/12/1776102.html http://blog.itpub.net/29485627/view ...
- 滑动页面,顶部导航or顶部 固定在一个位置
现在很多页面 特别是电商用的比较多 比如电商里面某个商品的详细页 往下拉页面 当滚轮到达一定位置的时候 导航栏即固定在顶部 其实他的原理很简单, 就是一开始设置导航为相对定位,然后计算出滚动条离顶部 ...
- 玩转iOS 9的UIDynamics(转)
转自 http://www.cocoachina.com/ios/20150716/12613.html 本文由CocoaChina翻译小组成员AGSpider(微博)翻译自fancypixel的博客 ...
- 二、C# 数据类型
C#语言的基本类型包括8种整数类型.2种用于科学计算的二进制浮点类型.1种用于金融计算的十 进制浮点类型.1种布尔类型以及1种字符类型. 2.1 基本数值类型 C#中的基本数据类型都有关键字和它们关联 ...
- 高级I/O函数(3)-tee、fcntl函数
tee函数使用 功能描述:tee函数在两个管道文件描述符之间复制数据,也是零拷贝操作.它不消耗数据,因此源文件描述符仍然可以用于后续的操作. 函数原型: #include <fcntl.h> ...
- mybatis 学习笔记(4) —— 批量新增数据
1.业务是从前台传入List<T> ,在controller层接受参数,并进行批量新增操作. 2.需要处理的细节 a) mybatis可以支持批量新增,注意数据表需要将主键设置成自增列. ...
- JQuery验证input
jsp中表单如下: <form method="post" action="AddPlayer"> <div class = "on ...
- 常用排序算法总结(C#版)
首先,说说几个排序中的概念. 1.稳定排序和非稳定排序 简单地说就是所有相等的数经过某种排序方法后,仍能保持它们在排序之前的相对次序,我们就说这种排序方法是稳定的.反之,就是非稳定的. 比如:一组数 ...
- js中typeof的用法
一. 经常会在js里用到数组,比如 多个名字相同的input, 若是动态生成的, 提交时就需要判断其是否是数组. if(document.mylist.length != "undefine ...
- SQL语句宝典
1.前述: 将数据灵活运用于手掌心! link:1.经典SQL语句大全(cnblogs) 2.SQL教程(W3C)