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



0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 淡奶油发过了怎么办 打好的蛋清有水怎么办 想戒烟却坚持不了怎么办 给淮山弄的很痒怎么办 淮山接触皮肤痒怎么办 洗山药后手很痒怎么办 公司老板跑路了怎么办 小工厂老板跑路怎么办 学生医保卡丢了怎么办 在私企年龄大了怎么办 百度网盘上传慢怎么办 百度云盘上传慢怎么办 手机qq打字闪退怎么办 苹果5s手机闪退怎么办 手机qq总是闪退怎么办 qq邮箱密码忘了怎么办 qq加不了群怎么办视频 孩子好几天不大便怎么办 宝宝7天没有大便怎么办 40天小孩不拉屎怎么办 40多天婴儿便秘怎么办 小孩拉绿色稀便怎么办 5岁好几天不拉屎怎么办 2个月宝宝不大便怎么办 两月宝宝不拉屎怎么办 好几天没大便了怎么办 初生婴儿便秘解不出大便怎么办 小孩大便拉不出来怎么办 新生儿3天没大便怎么办 新生儿5天没大便怎么办 小孩好几天不大便怎么办 婴儿10天不拉屎怎么办 3岁大便拉不出来怎么办 孩子大便拉不出来怎么办 4岁大便拉不出来怎么办 排位队友太坑怎么办 lol遇到坑b队友怎么办 被冷暴力分手后怎么办 孕早期半夜饿了怎么办 怀孕了月经还来怎么办 大米生虫子吃了怎么办