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. gridview动态添加列的问题

    相信大家也和我一样遇到过这种问题,gridview在生成列的时候当列不确定怎么办?下面分享一下自己的解决方法. 举个列子说明一下. 普通列的添加比较简单. BoundField bf = new Bo ...

  2. js的定位实现和ip查询

    sina的api var GetLocationFromSina = function (successFunc, errorFunc) { $.getScript('http://int.dpool ...

  3. 弹出层easydialog-v2.0

    地址:http://www.lanrentuku.com/down/js/qita-862/ easydialog.css ;;; } .easyDialog_wrapper{ width:320px ...

  4. Html5 Canvas Text

    html5 canvas中支持对text文本进行渲染;直接的理解就是把text绘制在画布上,并像图形一样处理它(可以加shadow.gradient.pattern.color fill等等):既然它 ...

  5. MySQL DELETE

    MySQL DELETE 语句 你可以使用 SQL 的 DELETE FROM 命令来删除 MySQL 数据表中的记录. 你可以在mysql>命令提示符或PHP脚本中执行该命令. 语法 以下是S ...

  6. Asp.Net 母版页

    背景:回顾下以前用到过的asp.net控件 介绍: 使用 ASP.NET 母版页可以为应用程序中的页创建一致的布局.单个母版页可以为应用程序中的所有页(或一组页)定义所需的外观和标准行为.然后可以创建 ...

  7. 重新开始学习javase_集合_Map

    一,Map之HashMap(转:http://blog.csdn.net/zheng0518/article/details/42197049) 1.    HashMap概述: HashMap是基于 ...

  8. Ajax.BeginForm 防止跳转到新页面

    @using (Ajax.BeginForm("ChangeCompanyId", "navigation", new { area = "confi ...

  9. Python爬虫预备知识

    1.http编程知识 http中client 和server的工作模式 client和server建立可靠的tcp链接(在HTTP1.1中这个链接是长时间的,超时断开策略) client通过socke ...

  10. django 序列化json问题

    from django.core import serializers @login_required def ajax_get_data(request): json_data = serializ ...