加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 01:37:23 所属栏目:大数据 来源:网络整理
导读:我已经配置了一个弹簧的方法来调用之前的工作正常工作.现在我的要求是将此作业保持为持久性,这将在集群环境中运行. 将quartz配置为集群和持久性后,应用程序在部署时抛出以下异常: java.io.NotSerializableException: Unable to serialize JobDataMap for in

我已经配置了一个弹簧的方法来调用之前的工作正常工作.现在我的要求是将此作业保持为持久性,这将在集群环境中运行.
将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来解决了这个问题.配置如下:

但是,要在我的作业类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);
        ...
    }

}

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读