spring内集成quartz
来源:互联网 发布:税务网络学校 编辑:程序博客网 时间:2024/06/05 18:22
今天打算做一个自动定时任务,所以在网上看了一些关于quartz的资料配置,但是一直包错,错误信息如下:
Error creating bean with name 'configAnnotationBeanPostProcessor': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xx.hgdf.core.utils.props.config.CustomPropertyPlaceholderConfigurer com.xx.hgdf.core.utils.props.config.ConfigAnnotationBeanPostProcessor.propertyConfigurer; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.xx.hgdf.hbi.web.zb.sendWarnMessage] for bean with name 'quartzJob' defined in URL [file:/E:/hgoa4/hbi/adp/src/main/webapp/WEB-INF/classes/spring/spring-quartz.xml]; nested exception is java.lang.ClassNotFoundException: com.hongguaninfo.hgdf.hbi.web.zb.sendWarnMessage
其实在错误信息中已经指出了我的问题所在ClassNotFoundException,不过我一直没注意到这一点,总是纠结前面的报错信息.其实就是因为我使用的公司框架需要在任务执行对象(sendWarnMessage)使用注解,而我没有添加上去的 原因.
目前我的配置信息如下:
spring-quartz.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<bean id="quartzJob" class="com.xx.hgdf.hbi.web.zb.SendWarnMessage"></bean>
<bean id="tspAssetInfoSyncJob"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- <property name="targetObject" ref="quartzJob" /> -->
<property name="targetObject" >
<ref bean="quartzJob"/>
</property>
<property name="targetMethod" value="sendMessage" /><!-- 执行方法名称 -->
</bean>
<bean id="tspAssetInfoSyncService" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="tspAssetInfoSyncJob" />
<property name="cronExpression"><!-- 0 1 * * * ? 每天的每个小时的第一分钟触发 -->
<value>0/30 * * * * ?</value><!-- 0 1,10,20,40 6-18 * * ?job执行时间间隔 ,6-18点在1,10,20,40分钟时执行一次 -->
</property>
</bean>
<!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
<bean id="startQuertz" lazy-init="false" autowire="no"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="tspAssetInfoSyncService" />
</list>
</property>
</bean>
</beans>
SendWarnMessage对象:
package com.xx.hgdf.hbi.web.zb;
import org.springframework.stereotype.Component;
@Component(value="sendWarnMessage")
public class SendWarnMessage {//需要添加@Component 注解
// protected static final Log LOG = LogFactory.getLog(sendWarnMessage.class);
public void sendMessage(){
System.out.println("111111111111111");
}
}
最后在applicationContext.xml 中把spring-quartz.xml引入就可以了.
PS:其实所有的代码和网上的差不多,只是在对象SendWarnMessage.java上添加了@Component
- spring内集成quartz
- Spring 3 - Quartz - 集成
- Spring集成Quartz
- spring 3.0集成 quartz
- spring集成quartz
- Spring集成Quartz
- 集成spring和quartz
- Spring集成Quartz实战
- spring集成quartz
- spring集成 quartz
- Spring集成quartz
- Quartz集成Spring框架
- spring-boot集成Quartz
- Quartz+Spring集成配置
- spring集成quartz
- Spring中集成quartz
- Quartz的spring集成
- Spring 集成Quartz
- MEAN全栈开发:使用NodeJS和MongoDB创建REST服务
- Hadoop数据收集与入库系统Flume与Sqoop
- 连载:面向对象葵花宝典:思想、技巧与实践(6) - 不要说你懂“类”
- SQL Server中如何找出执行时间过长的作业
- 如何创建一个SAP的销售订单
- spring内集成quartz
- Fibonacci sequence_纪中1240_矩阵乘法
- Android Ui卡顿检测
- IntelliJ IDEA2016.1 + maven 创建java web 项目
- git 学习
- GTKFB
- HoughCircles---一些好的文章
- VC CString
- OS X包管理工具——Homebrew