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 ...
随机推荐
- Unix Shell 通配符、转义字符、元字符、特殊字符
shell通配符: * 匹配0或多个字符 a*b a与b之间可以有任意长度的任意字符, 也可以一个也没有, 如aabcb, a01b, ab等 ? 匹配任意一个字符 a?b a与b之间有且只有一个字符 ...
- 洛谷 P1273 有线电视网(dp)
/* 想了半天没想出状态 自己还是太弱了 QAQ 题目问的是最多供给多少户 一般想法是把这个值定义为状态量 没想出来QAQ....看了看题解的状态 很机智.... f[i][j]表示i的子树 选了j个 ...
- Linq 实现普通sql中 where in 的功能
user.ProjectIds 的值是使用逗号分隔的 例如:1,2,3 projectList = (from a in projectList where (user.ProjectIds.Spli ...
- ubuntu远程连接
apt-cache search openssh-server //直接用apt-get install openssh-server安装.记不清包名字时可用apt-cache search o ...
- addEventListener之handleEvent
addEventListener() 方法是将指定的事件监听器注册到目标对象上,当该对象触发指定的事件时,指定的回调函数就会被执行.语法: element.addEventListener(type, ...
- php 与 ajax 获取123的案例
同事问我,咱们从数据库里面获取数据,用ajax的方式展示到前台页面.啥都不说了,动手写个案例吧. 1,建立一个页面: <!DOCTYPE html PUBLIC "-//W3C//DT ...
- hdu1230火星A+B (大数题)
Problem Description 读入两个不超过25位的火星正整数A和B,计算A+B.需要注意的是:在火星上,整数不是单一进制的,第n位的进制就是第n个素数.例如:地球上的10进制数2,在火星上 ...
- 『重构--改善既有代码的设计』读书笔记----Split Temporary Variable
继续开始我们重构手法的系列,今天介绍的是Split Temporary Variable---分解临时变量. 在我们平常写的程序中肯定有某些临时变量被赋予了超过一个的责任.如果他们不是那种收集结果(t ...
- 移动端html5重力感应
下面是测试案例,只测试过itouch,iphone http://06wjin.sinaapp.com/billd/ http://06wjin.sinaapp.com/billd/test. ...
- python之sys模块
38.python的sys模块: 用于提供对Python解释器相关的操作: 1 2 3 4 5 6 7 8 9 sys.argv 命令行参数List,第一个元素是程序本身路径 sy ...