Problem with persistent quartz jobs when used with Spring

I configured the spring method, which previously ran a job that works fine. Now my requirement is that this work be permanent, which will work in a cluster environment. After configuring quartz as a cluster and persistent application, the application deploys the following exception:

java.io.NotSerializableException: Cannot serialize JobDataMap to insert into database because the value of the 'methodInvoker' property is not serializable: org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean

I use the following versions:

  • Spring version 3.1.4.RELEASE
  • Quartz version 2.1.7

Update : according to the documentation MethodInvokingJobDetailFactoryBean:

JobDetails created via this FactoryBean are not serializable.

So, we are looking for an alternative approach for setting up constant work in spring.

+4
source share
2 answers

I solved the problem by replacing MethodInvokingJobDetailFactoryBeanwith JobDetailFactoryBean. The configuration for it is as follows:

<bean name="myJob" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
    <property name="jobClass" value="mypackage.MyJob" />
    <property name="group" value="MY_JOBS_GROUP" />
    <property name="durability" value="true" />
</bean>

However, for Autowirespring managed beans in my job class, mypackage.MyJobI added the following as the first line in my execution method:

class MyJob implements Job {
    ...
    public void execute(final JobExecutionContext context) throws JobExecutionException {
        // Process @Autowired injection for the given target object, based on the current web application context. 
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
        ...
    }

}

Hope this helps someone else facing the same problem.

+6
source

When you use constant quartz jobs, you must set the property org.quartz.jobStore.usePropertiesto true. This forces the job data to be saved as strings instead of Java Serialized objects.

Spring, .

:

http://site.trimplement.com/using-spring-and-quartz-with-jobstore-properties/

http://forum.spring.io/forum/spring-projects/container/121806-quartz-error-ioexception

+6

Source: https://habr.com/ru/post/1539246/


All Articles