Reputation: 103
upgrading to spring 4.2.5 has caused a startup problem around quartz scheduler -
NoSuchMethodError : org.quartz.Scheduler.getListenerManager()
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'intAppService' defined in file [SaPvApp-context.xml]: Cannot resolve reference to bean 'quartzScheduler' while setting bean property 'quartzScheduler'; nested exception is org.springframework.beans.factory.Bean
CreationException: Error creating bean with name 'quartzScheduler' defined in file [C:\Integration Apps\SAPV\config\SaPvApp-context.xml]:
Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.quartz.Scheduler.getListenerManager()Lorg/quartz/ListenerManager;
from pom:
<dependency>
<groupId>org.opensymphony.quartz</groupId>
<artifactId>quartz</artifactId>
<version>1.6.5</version>
</dependency>
from context file:
<bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup" value="false" />
<property name="schedulerName" value="PvScheduler" />
<property name="triggers">
<list>
<!-- <ref bean="cronTrigger" /> -->
</list>
</property>
</bean>
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="serviceTask" />
<property name="targetMethod" value="run" />
<property name="concurrent" value="false" />
<property name="group" value="PV" />
<property name="name" value="${app.service.name}${app.service.instance}-Job" />
<property name="jobListenerNames">
<list>
<!-- <value>PvJobListener</value> -->
</list>
</property>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<!--<property name="cronExpression" value="10 0/01 * * * ?" />-->
<!-- run twice a day at 3am and 3pm -->
<property name="cronExpression" value="0 0 3,15 ? * *" />
<!-- run every 30 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:30:10 am, etc.)
<property name="cronExpression" value="10 0/30 * * * ?" /> -->
</bean>
edit: attempting to upgrade quartz to 2.2.2:
/**
* Listen for Job and Scheduler events.
*/
public void listen() {
if (this.quartzScheduler != null) {
try {
this.quartzScheduler.addJobListener(this);
this.quartzScheduler.addSchedulerListener(this);
}
catch (SchedulerException e) {
throw new IntegrationServiceException("listen", e);
}
}
}
Errors:
The method addJobListener(QuartzTaskScheduler) is undefined for the type Scheduler
The method addSchedulerListener(QuartzTaskScheduler) is undefined for the type Scheduler
Edit 4/3/17: I was able to resolve the abstract error by adding abstract=”true” to my bean definition however, i'm getting a new error posted below:
Error creating bean with name 'jobDetail' defined in file [C:\Integration Apps\SAPV\config\SaPvApp-context.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jobListenerNames' of bean class
[org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean]: Bean property 'jobListenerNames' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1518)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:93)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:54)
at cmd.SaPvApp.main(SaPvApp.java:18)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'jobListenerNames' of bean class [org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean]: Bean property 'jobListenerNames' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:231)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:423)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:280)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:95)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
... 15 more
edit 4/3/17 pt2: I commented out jobListernersNames and got a new error:
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name 'cronTrigger' defined in file [C:\Integration Apps\SAPV\config\SaPvApp-context.xml]; nested exception is java.lang.ClassNotFoundException:
org.springframework.scheduling.quartz.CronTriggerBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1445)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:975)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:752)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:93)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:54)
at cmd.SaPvApp.main(SaPvApp.java:18)
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:394)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1344)
... 12 more
Here is the state of the context.xml file (note if I add back the ref to cronTrigger it gets my original error:
<bean name="intAppService" class="QuartzTaskScheduler" init-method="listen" abstract="true">
<property name="name" value="PvJobListener" />
<property name="quartzScheduler" ref="quartzScheduler"/>
</bean>
<bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup" value="false" />
<property name="schedulerName" value="PvScheduler" />
<property name="triggers">
<list>
<!--<ref bean="cronTrigger" />-->
</list>
</property>
</bean>
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="serviceTask" />
<property name="targetMethod" value="run" />
<property name="concurrent" value="false" />
<property name="group" value="PV" />
<property name="name" value="${app.service.name}${app.service.instance}-Job" />
<!--<property name="jobListenerNames">
<list>
<value>PvJobListener</value>
</list>
</property>-->
</bean>
<bean name="serviceTask" class="SaPvService">
<property name="serviceTaskName" value="${app.service.name}${app.service.instance}"/>
<property name="hoursRepository" ref="hoursRepository"/>
<property name="primaveraSessionService" ref="primaveraSessionService"/>
<property name="resourceRateProcessor" ref="resourceRateProcessor"/>
<property name="workChunkRepository" ref="workChunkRepository"/>
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<!--<property name="cronExpression" value="10 0/01 * * * ?" />-->
<!-- run twice a day at 3am and 3pm -->
<property name="cronExpression" value="0 0 3,15 ? * *" />
<!-- run every 30 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:30:10 am, etc.)
<property name="cronExpression" value="10 0/30 * * * ?" /> -->
</bean>
edit 4/3/17 pt2 a: I put the cronTrigger ref back in this is the error for that situation:
context:
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<!--<property name="cronExpression" value="10 0/01 * * * ?" />-->
<!-- run twice a day at 3am and 3pm -->
<property name="cronExpression" value="0 0 3,15 ? * *" />
<!-- run every 30 minutes, at 10 seconds after the minute (i.e. 10:00:10 am, 10:30:10 am, etc.)
<property name="cronExpression" value="10 0/30 * * * ?" /> -->
</bean>
<bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="autoStartup" value="false" />
<property name="schedulerName" value="PvScheduler" />
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
</bean>
error:
2017-04-03 14:34:22,792 WARN {main} [org.springframework.context.support.FileSystemXmlApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name 'cronTrigger' defined in file [C:\Integration Apps\SAPV\config\SaPvApp-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean
*** SaPvApp: Unexpected service error at Mon Apr 03 14:34:23 CDT 2017
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.scheduling.quartz.CronTriggerBean] for bean with name 'cronTrigger' defined in file [C:\Integration Apps\SAPV\config\SaPvApp-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1352)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:597)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1445)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:975)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:752)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:93)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:54)
at cmd.SaPvApp.main(SaPvApp.java:18)
Caused by: java.lang.ClassNotFoundException: org.springframework.scheduling.quartz.CronTriggerBean
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:394)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1344)
... 12 more
update 4/3/17 14:55 CT: I changed the context file CronTriggerBean is now CronTriggerFactoryBean now i'm getting this error:
2017-04-03 14:52:47,570 INFO {main} [org.quartz.core.QuartzScheduler] -
Scheduler meta-data: Quartz Scheduler (v2.2.2) 'PvScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
2017-04-03 14:52:47,572 INFO {main} [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler 'PvScheduler' initialized from an externally provided properties instance.
2017-04-03 14:52:47,574 INFO {main} [org.quartz.impl.StdSchedulerFactory] - Quartz scheduler version: 2.2.2
2017-04-03 14:52:47,576 INFO {main} [org.quartz.core.QuartzScheduler] - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@749ad37c
*** SaPvApp: Registering JVM shutdown hook
*** SaPvApp: version 17.1.0
*** SaPvApp: Adding service-stop event listeners
*** SaPvApp: Starting service at Mon Apr 03 14:52:47 CDT 2017
*** SaPvApp: Unexpected service error at Mon Apr 03 14:52:47 CDT 2017
org.springframework.beans.factory.BeanIsAbstractException: Error creating bean with name 'intAppService': Bean definition is abstract
at org.springframework.beans.factory.support.AbstractBeanFactory.checkMergedBeanDefinition(AbstractBeanFactory.java:1288)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:285)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:112)
at AbstractCommandLineApplication.runApplication(AbstractCommandLineApplication.java:54)
at cmd.SaPvApp.main(SaPvApp.java:18)
*** SaPvApp: Calling service stop event listeners
*** SaPvApp: Exiting service at Mon Apr 03 14:52:47 CDT 2017
*** SaPvApp ShutdownHook: Service shutdown initiated at Mon Apr 03 14:52:47 CDT 2017
*** SaPvApp ShutdownHook: Closing application context
2017-04-03 14:52:47,609 INFO {ApplicationShutdownHook} [org.springframework.context.support.FileSystemXmlApplicationContext] - Closing org.springframework.context.support.FileSystemXmlApplicationContext@63e31ee: startup date [Mon Apr 03 14:52:41 CDT 2017]; root of context hierarchy
2017-04-03 14:52:47,615 INFO {ApplicationShutdownHook} [org.springframework.context.support.DefaultLifecycleProcessor] - Stopping beans in phase 2147483647
2017-04-03 14:52:47,618 INFO {ApplicationShutdownHook} [org.springframework.scheduling.quartz.SchedulerFactoryBean] - Shutting down Quartz Scheduler
2017-04-03 14:52:47,619 INFO {ApplicationShutdownHook} [org.quartz.core.QuartzScheduler] - Scheduler PvScheduler_$_NON_CLUSTERED shutting down.
2017-04-03 14:52:47,620 INFO {ApplicationShutdownHook} [org.quartz.core.QuartzScheduler] - Scheduler PvScheduler_$_NON_CLUSTERED paused.
2017-04-03 14:52:47,621 INFO {ApplicationShutdownHook} [org.quartz.core.QuartzScheduler] - Scheduler PvScheduler_$_NON_CLUSTERED shutdown complete.
*** SaPvApp ShutdownHook: Service shutdown complete
edit 4/4/17 07:59: I tried creating a parent abstract class
<bean name="intAppServiceParent" abstract = "true">
<property name="nameParent" value="PvJobListenerParent" />
<property name="quartzSchedulerParent" ref="quartzSchedulerParent"/>
</bean>
<bean name="intAppService" class="QuartzTaskScheduler" init-method="listen" parent = "intAppServiceParent">
<property name="name" value="PvJobListener" />
<property name="quartzScheduler" ref="quartzScheduler"/>
</bean>
but I'm getting this error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'intAppService' defined in file [C:\Integration Apps\SAPV\config\SaPvApp-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [QuartzTaskScheduler]: Is it an abstract class?; nested exception is java.lang.InstantiationException
If I don't make the java code class abstract I get a compile error about this:
The type QuartzTaskScheduler must implement the inherited abstract method SchedulerListener.triggersPaused(String)
I'm not sure how to fix this?
Upvotes: 2
Views: 8057
Reputation: 11865
I'm posting solution steps scattered in comments as an answer to make it easier to find those steps.
Some of the steps required to upgrade to Spring 4.2.5 having Quartz integration:
addJobListener()
and addSchedulerListener()
methods were moved from QuartzScheduler
to ListenerManager
which is available via getListenerManager()
method.setJobListenerNames()
method was removed, so jobListenerNames
should not be set in XML configuration.Upvotes: 3
Reputation: 103
in addition to upgrading spring and quartz I needed to modify java code specifically around QuartzTaskScheduler since the upgrade the code did not implement all the abstract methods. I had to implement them all. It is probably because its parent class has been changed, so new abstract methods were added, or signatures of some methods were changed.
Upvotes: 0
Reputation: 3564
Your overriden quartz version is not compatible with the version of Springs. Remove quartz version declaration from your pom Or try to upgrade the quartz version to 2.2.2 which is supported by Spring context 4.2.5.
Upvotes: 0