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整合的更多相关文章

  1. Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码)

    Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合(注解及源码) 备注: 之前在Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合中 ...

  2. 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 ...

  3. spring3.0的BeanFactory上下文context获取不到bean

    开门见山,背景: 系统初始化的时候扫包实例化bean,然后一个工具类实现ServletContextAware接口,拿到servletContext之后: WebApplicationContextU ...

  4. 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 ...

  5. Spring3 + Spring MVC+ Mybatis 3+Mysql 项目整合

    项目环境背景: 操作系统:win7 JDK:1.7 相关依赖包,截图如下:

  6. Spring3.2.11与Quartz2.2.1整合时内存泄漏的问题的解决

    Quartz是一款定时任务调度的开源框架,使用起来比较方便.并且Spring的support包对Quartz有集成.但是笔者在web应用使用的过程中却遇到了内存泄漏的问题. 问题的产生 笔者在使用Sp ...

  7. Maven 整合 spring profile实现多环境自动切换

    Maven 整合 spring profile实现多环境自动切换 时间:2014-03-19 15:32来源:Internet 作者:Internet 点击:525次 profile主要用在项目多环境 ...

  8. mybatis0211 mybatis和spring整合

    1mybatis和spring整合 1.1 mybaits和spring整合的思路 .让spring管理SqlSessionFactory .让spring管理mapper动态代理对象和dao. 使用 ...

  9. [转]基于全注解的Spring3.1 mvc、myBatis3.1、Mysql的轻量级项目

    摘要 对于现在主流的j2ee企业级开发而言,ssh(struts+hibernate+spring)依然是一个事实的标准.由struts充当的mvc调度控制:hibernate的orm持久化映射:sp ...

随机推荐

  1. require.js的使用的坑!

    require.js的使用心德: 都是自我的理解所得: first:为什么使用? 1,web开发js的占用比例越来越大,引入的插件也越来越多,维护困难,一个一个的script的写要废 2,模块开发的需 ...

  2. PHP 实现无限极栏目分类

    首先,创建一个DB CREATE TABLE IF NOT EXISTS `class` ( `id` mediumint(6) NOT NULL AUTO_INCREMENT, `title` va ...

  3. LinkButton和HyperLink的页面跳转用法

    <%--<asp:HyperLink ID="HyperLink1" NavigateUrl='<%#"/Fxy_Admin/Pro_ClassNew. ...

  4. ManagementException:WMI异常处理介绍

    .NET调用WMI后无论是同步调用还是异步调用,都会产生返回一个int类型的执行结果.如果成功,则返回0.如果不是0,则有对应错误码表示发生了什么错误. 根据咱们这个系列的博文,我总结了关于进程,服务 ...

  5. oracle事务特性详解

    原子性 事务是一个完整的操作.事务的各步操作是不可分的(原子的):要么都执行,要么都不执行. -- 创建表 create table account_money ( id number(4) not ...

  6. 【USACO 2.3.1】最长前缀

    [题目描述] 在生物学中,一些生物的结构是用包含其要素的大写字母序列来表示的.生物学家对于把长的序列分解成较短的序列(即元素)很感兴趣. 如果一个集合 P 中的元素可以通过串联(元素可以重复使用,相当 ...

  7. 谈谈PHP、Python与Ruby

    假如你想帮他尽快找个活儿,赚到钱,推荐PHP. 假如你想让他成为一个高效工程师,推荐 Python. 假如你想让他爱上他的工作,推荐 Ruby. 语言的选择 编程语言非常重要,不要认为他们都图灵等价, ...

  8. VirtualBox开发环境的搭建详解(转)

    VirtualBox开发环境的搭建详解   有关VirtualBox的介绍请参考:VirtualBox_百度百科 由于VirtualBox官网提供的搭建方法不够详细,而且本人在它指导下,从下载所需的开 ...

  9. Spring4.0学习笔记(10) —— Spring AOP

    个人理解: Spring AOP 与Struts 的 Interceptor 拦截器 有着一样的实现原理,即通过动态代理的方式,将目标对象与执行对象结合起来,降低代码之间的耦合度,主要运用了Proxy ...

  10. 解决VS2010使用comboBox死机问题

    今天,在10下使用combobox总是不响应,原来是和翻译软件冲突,关掉有道立即解决.