微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Spring时与Quartz持久作业有关的问题

我已经配置了一个弹簧的方法调用之前的工作正常工作.现在我的要求是将此作业保持为持久性,这将在集群环境中运行.
将quartz配置为集群和持久性后,应用程序在部署时抛出以下异常:

java.io.NotSerializableException: Unable to serialize JobDataMap for
insertion into database because the value of property ‘methodInvoker’
is not serializable:
org.springframework.scheduling.quartz.MethodInvokingJobDetailfactorybean

我使用以下版本:

> Spring版本3.1.4.RELEASE
> Quartz 2.1.7版

更新:根据MethodInvokingJobDetailfactorybean的文档:

JobDetails created via this factorybean are not serializable.

因此,寻找一些在Spring中配置持久作业的替代方法.

最佳答案
我通过将JobInvokingJobDetailfactorybean替换为JobDetailfactorybean解决了这个问题.配置如下:

factorybean">
    

但是,要在我的作业类mypackage.MyJob中自动装配spring托管bean,我在执行方法添加了以下内容作为第一行:

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);
        ...
    }

}

希望它能帮助其他人面对同样的问题.

原文地址:https://www.jb51.cc/spring/431814.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐