我的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="scheduleDetail"
class="test.quartz.ScheduleDetail">
</bean>
<bean id="jobBean"
class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="test.quartz.QuartzTest"/>
</bean>
<bean id="crontrigger"
class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="jobBean"/>
</property>
<property name="cronExpression">
<value>
30 * * * * *
</value>
</property>
</bean>
<bean id="trigger"
class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="jobBean"/>
</property>
<property name="repeatInterval">
<value>3000</value>
</property>
</bean>
<bean id="scheduler"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="trigger"/>
<!--这个注释掉后能正常运行simpletrigger-->
<ref bean="crontrigger"/>
</list>
</property>
</bean>
如果没有注释报如下错误.
log4j:WARN File option not set for appender [FILE].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scheduler' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.util.NoSuchElementException]
Caused by: org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.util.NoSuchElementException]
at org.springframework.scheduling.quartz.SchedulerFactoryBean.registerJobsAndTriggers(SchedulerFactoryBean.java:808)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.afterPropertiesSet(SchedulerFactoryBean.java:612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1198)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1167)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:427)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:285)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:122)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
at test.quartz.Test.main(Test.java:11)
Caused by: java.util.NoSuchElementException
at java.util.TreeMap.key(TreeMap.java:1206)
at java.util.TreeMap.firstKey(TreeMap.java:267)
at java.util.TreeSet.first(TreeSet.java:377)
at org.quartz.CronExpression.getTimeAfter(CronExpression.java:1062)
at org.quartz.CronTrigger.getTimeAfter(CronTrigger.java:903)
at org.quartz.CronTrigger.getFireTimeAfter(CronTrigger.java:612)
at org.quartz.CronTrigger.computeFirstFireTime(CronTrigger.java:882)
at org.quartz.core.QuartzScheduler.scheduleJob(QuartzScheduler.java:742)
at org.quartz.impl.StdScheduler.scheduleJob(StdScheduler.java:266)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.addTriggerToScheduler(SchedulerFactoryBean.java:859)
at org.springframework.scheduling.quartz.SchedulerFactoryBean.registerJobsAndTriggers(SchedulerFactoryBean.java:789)
... 13 more
</beans>
5 个解决方案
#1
注册触发器失败
#2
是的.错误应该就在这里
Error creating bean with name 'scheduler' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.util.NoSuchElementException]
我试了,trigger,jobbean都能得到.但为什么不能注册到scheduler里面去呢???
这个NULL不知道是JOB为空还是TRIGGER为空.迷惑...
Error creating bean with name 'scheduler' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.util.NoSuchElementException]
我试了,trigger,jobbean都能得到.但为什么不能注册到scheduler里面去呢???
这个NULL不知道是JOB为空还是TRIGGER为空.迷惑...
#3
怎么没人回啊,已经找到问题的原因了.
是这里<value>
30 * * * * *
</value>
不能分开写,正确的格式应该是<value>30 * * * * *</value>.最后的不能为*,为?的时候能正常工作.
哪位可以帮忙解释否?
是这里<value>
30 * * * * *
</value>
不能分开写,正确的格式应该是<value>30 * * * * *</value>.最后的不能为*,为?的时候能正常工作.
哪位可以帮忙解释否?
#4
#1
注册触发器失败
#2
是的.错误应该就在这里
Error creating bean with name 'scheduler' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.util.NoSuchElementException]
我试了,trigger,jobbean都能得到.但为什么不能注册到scheduler里面去呢???
这个NULL不知道是JOB为空还是TRIGGER为空.迷惑...
Error creating bean with name 'scheduler' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.quartz.SchedulerException: Registration of jobs and triggers failed: null [See nested exception: java.util.NoSuchElementException]
我试了,trigger,jobbean都能得到.但为什么不能注册到scheduler里面去呢???
这个NULL不知道是JOB为空还是TRIGGER为空.迷惑...
#3
怎么没人回啊,已经找到问题的原因了.
是这里<value>
30 * * * * *
</value>
不能分开写,正确的格式应该是<value>30 * * * * *</value>.最后的不能为*,为?的时候能正常工作.
哪位可以帮忙解释否?
是这里<value>
30 * * * * *
</value>
不能分开写,正确的格式应该是<value>30 * * * * *</value>.最后的不能为*,为?的时候能正常工作.
哪位可以帮忙解释否?