Spring+Quartz 'jobLauncher' is not serializable
来源:互联网 发布:淘宝质量好的鞋店 编辑:程序博客网 时间:2024/05/20 05:45
Unable to serialize JobDataMap for insertion into database because the value of property 'jobLauncher' is not serializable
1.问题:quartz启用数据库管理模式,启动时报异常
【java.io.NotSerializableException: Unable to serialize JobDataMap for insertion into database because the value of property 'jobLauncher' is not serializable: org.springframework.batch.core.launch.support.SimpleJobLauncher】
2.原因:quartz使用数据库管理模式,需要将配置信息进行序列化,保存到数据库,而spring的SimpleJobLauncher是不支持序列化的.
配置如下:
<bean id="automatchJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean"><property name="jobClass" value="com.kiosk.datacollect.quartz.QuartzJob" /><property name="group" value="quartz-batch-auto" /><property name="jobDataAsMap"><map> <entry key="jobName" value="" /> <entry key="jobLocator" value-ref="jobRegistry" /> <entry key="jobLauncher" value-ref="jobLauncher" /></map></property></bean>
3.解决:
在spring的SchedulerFactoryBean类的源码里,有这样一段注释,大意是 当使用持久化的job,将jobdetail保存到数据库中,不要将spring管理的bean或是ApplicationContext的引用配置到JobDataMap中,而是通过schedulerContextAsMap参数将其配置到SchedulerContext(也就是Scheduler的上下文)
<bean id="scheduler" lazy-init="true" autowire="no"class="org.springframework.scheduling.quartz.SchedulerFactoryBean"><property name="autoStartup" value="true" /><property name="triggers"><list><bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"><property name="jobDetail" ref="collectDataJobDetail" /><property name="cronExpression" value="10,20,30 * * * * ?" /></bean> </list></property> <!-- 解决:quartz启用数据库管理模式,启动时报异常【java.io.NotSerializableException: Unable to serialize JobDataMap for insertion into database because the value of property 'jobLauncher' is not serializable: org.springframework.batch.core.launch.support.SimpleJobLauncher】 --><property name="schedulerContextAsMap"><map><entry key="jobLocator" value-ref="jobRegistry" /><entry key="jobLauncher" value-ref="jobLauncher" /></map></property><!--可选,QuartzScheduler 启动时更新己存在的Job,这样就不用每次修改targetObject后删除qrtz_job_details表对应记录了 --> <property name="overwriteExistingJobs" value="true"/><!-- 属性 --><property name="quartzProperties"><props><!-- 集群要求必须使用持久化存储 --><prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreCMT</prop> <prop key="org.quartz.scheduler.instanceName">EventScheduler</prop><!-- 每个集群节点要有独立的instanceId --><prop key="org.quartz.scheduler.instanceId">AUTO</prop><!-- Configure ThreadPool --><prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop><prop key="org.quartz.threadPool.threadCount">50</prop><prop key="org.quartz.threadPool.threadPriority">5</prop><prop key="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread">true</prop><!-- Configure JobStore --><prop key="org.quartz.jobStore.misfireThreshold">60000</prop><prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop><prop key="org.quartz.jobStore.tablePrefix">qrtz_</prop><prop key="org.quartz.jobStore.maxMisfiresToHandleAtATime">10</prop><!-- 开启集群 --><prop key="org.quartz.jobStore.isClustered">true</prop><prop key="org.quartz.jobStore.clusterCheckinInterval">5000</prop><prop key="org.quartz.jobStore.dontSetAutoCommitFalse">true</prop><prop key="org.quartz.jobStore.txIsolationLevelSerializable">false</prop><prop key="org.quartz.jobStore.dataSource">myDS</prop><prop key="org.quartz.jobStore.nonManagedTXDataSource">myDS</prop><prop key="org.quartz.jobStore.useProperties">false</prop><!-- Configure Datasources --><prop key="org.quartz.dataSource.myDS.driver">com.mysql.jdbc.Driver</prop><prop key="org.quartz.dataSource.myDS.URL">jdbc:mysql://192.168.28.128:3307/quartz</prop><prop key="org.quartz.dataSource.myDS.user">admin</prop><prop key="org.quartz.dataSource.myDS.password">admin</prop><prop key="org.quartz.dataSource.myDS.maxConnections">10</prop><prop key="org.quartz.dataSource.myDS.validationQuery">select 0 from qrtz_locks</prop></props></property><property name="applicationContextSchedulerContextKey" value="applicationContext" /></bean>
4.第二种解决方式:
1、jobLauncher创建新类,继承
org.springframework.batch.core.launch.support.SimpleJobLauncher,并实现接口Serializable
jobRegistry创建新类继承org.springframework.batch.core.configuration.support.MapJobRegistry,并实现接口Serializable
- Spring+Quartz 'jobLauncher' is not serializable
- ehcache Key is not Serializable
- TypeError: ObjectId('') is not JSON serializable
- datetime.datetime() is not JSON serializable
- spark + quartz : org.apache.spark.SparkException: Task not serializable
- [Python]json 错误xx is not JSON serializable
- python datetime.datetime is not JSON serializable 报错问题解决
- python datetime.datetime is not JSON serializable 报错问题解决
- XXX is not JSON serializable 另类解决方式
- 【已解决】Object of type 'range' is not JSON serializable
- 【已解决】Object of type 'QuerySet' is not JSON serializable
- Spring is not a distributed object model
- Spring AOP Interceptor transaction is not working
- spring quartz Could not open JDBC Connection for transaction; 错误
- he method get(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments
- datetime.datetime(2014, 1, 23, 21, 6, 37) is not JSON serializable
- storm启动问题解析Storm conf is not valid. Must be json-serializable
- datetimeTypeError: datetime.datetime(2015, 1, 29, 8, 17, 41) is not JSON serializable
- [收藏] solr 5.5 设置访问密码
- 学习RSS
- 嵌智捷达科技产品型号:CM-i.MX7D核心板
- 真传奇:看看这群清华学生的牛X岁月
- Django分页Paginator
- Spring+Quartz 'jobLauncher' is not serializable
- JavaScript获取浏览器高度和宽度值
- Android截屏实现——亲测有效代码
- bzoj1861 [Zjoi2006]Book 书架
- tomcat的server.xml详解
- Flume架构(一)
- [luogu]P1576最小花费-最短路裸题
- Python bottle 笔记(三) —— route
- (算法分析Week16)132 Pattern[Medium]