凌云兜儿 2016-01-13 08:40 采纳率: 0%
浏览 4753

quartz持久化到数据库

quartz在项目启动时,是不是会根据配置文件自动持久化到数据库,我的配置如下:

<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
     <property name="dataSource" ref="dataSource" />
    <property name="configLocation" value="classpath:properties/quartz.properties" />
    <property name="autoStartup" value="true" />
    <property name="applicationContextSchedulerContextKey" value="applicationContext" />
    <property name="startupDelay" value="20" />
    <property name="overwriteExistingJobs" value="true" />
    <property name="triggers">
        <list>
            <!-- 触发器列表 -->
            <ref bean="helloJobTrigger" />
        </list>
    </property>
</bean>

<bean id="helloJobBean" class="com.maidou.job.HelloJob"/>

<!-- 触发器 -->
<bean id="helloJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="helloJobDetail" />
    <property name="cronExpression" value="0/5 * * * * ?" />
    <!--<property name="group" value="group1"/>-->
    <property name="name" value="helloJobTrigger"/>
    <property name="volatility" value="true"/>
</bean>

<!--<bean id="helloJobDetail"-->
        <!--class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">-->
<bean id="helloJobDetail"
        class="com.maidou.factory.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="helloJobBean" />
    <property name="targetMethod" value="execute" />
    <property name="concurrent" value="false" />
    <property name="durable" value="true"/>
    <property name="volatility" value="true"/>
    <property name="shouldRecover" value="true" />
</bean>

可以连接到数据库,数据库是初始化时建的表,没有添加过数据
在运行时报如下错误:
信息: Loading Quartz config from [class path resource [properties/quartz.properties]]
2016-1-13 16:19:33 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl info
信息: {dataSource-1} inited
2016-1-13 16:19:34 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
信息: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@a98ce7e: defining beans [org.springframework.scheduling.quartz.SchedulerFactoryBean#0,helloJobBean,helloJobTrigger,helloJobDetail,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource]; root of factory hierarchy
2016-1-13 16:19:34 com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl info
信息: {dataSource-1} closed
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' defined in class path resource [spring-quartz.xml]: Invocation of init method failed; nested exception is org.quartz.JobPersistenceException: Couldn't store trigger 'helloJobTrigger' for 'helloJobDetail' job:The job (DEFAULT.helloJobDetail) referenced by the trigger does not exist. [See nested exception: org.quartz.JobPersistenceException: The job (DEFAULT.helloJobDetail) referenced by the trigger does not exist.]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at com.maidou.test.main(test.java:13)
Caused by: org.quartz.JobPersistenceException: Couldn't store trigger 'helloJobTrigger' for 'helloJobDetail' job:The job (DEFAULT.helloJobDetail) referenced by the trigger does not exist. [See nested exception: org.quartz.JobPersistenceException: The job (DEFAULT.helloJobDetail) referenced by the trigger does not exist.]
at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1270)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$5.execute(JobStoreSupport.java:1176)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$40.execute(JobStoreSupport.java:3716)
at org.quartz.impl.jdbcjobstore.JobStoreCMT.executeInLock(JobStoreCMT.java:242)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.executeInLock(JobStoreSupport.java:3712)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1172)
at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:870)
at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:254)
at org.springframework.scheduling.quartz.SchedulerAccessor.addTriggerToScheduler(SchedulerAccessor.java:356)
at org.springframework.scheduling.quartz.SchedulerAccessor.registerJobsAndTriggers(SchedulerAccessor.java:287)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 12 more
Caused by: org.quartz.JobPersistenceException: The job (DEFAULT.helloJobDetail) referenced by the trigger does not exist.
at org.quartz.impl.jdbcjobstore.JobStoreSupport.storeTrigger(JobStoreSupport.java:1231)
... 24 more

但是我在数据库添加qrtz_job_details表添加上job后,但是job_data是持久化数据,没有填,启动没有错,但是job不执行,这样的情况请问各位大神如何解决?
  • 写回答

2条回答

  • devmiao 2016-01-13 15:56
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值