JobRunr在调度Java后台作业时出现异常。

huangapple go评论106阅读模式
英文:

JobRunrException when scheduling java background job

问题

我们正在使用 JobRunr 在Java中进行一些后台作业处理。

我们按以下方式将作业加入队列:

CalendarEntry calendarEntry = new CalendarEntry("Quatuor Ebène", LocalDateTime.of(2020, 9, 16, 20, 0, 0).toInstant(ZoneOffset.UTC));
jobScheduler.enqueue(() -> calendarService.createCalendarEntry(calendarEntry));

在调度作业时,我们收到以下异常... 有什么想法是怎么回事?

您是否注册了所有必需的Jackson模块?
org.jobrunr.JobRunrException: 您是否注册了所有必需的Jackson模块?
	at org.jobrunr.JobRunrException.configurationException(JobRunrException.java:56)
	at org.jobrunr.utils.mapper.jackson.JacksonJsonMapper.deserialize(JacksonJsonMapper.java:76)
	at org.jobrunr.jobs.mappers.JobMapper.deserializeJob(JobMapper.java:20)
	at org.jobrunr.storage.InMemoryStorageProvider.deepClone(InMemoryStorageProvider.java:243)
	at org.jobrunr.storage.InMemoryStorageProvider.saveJob(InMemoryStorageProvider.java:259)
	at org.jobrunr.storage.InMemoryStorageProvider.save(InMemoryStorageProvider.java:109)
	at org.jobrunr.scheduling.JobScheduler.saveJob(JobScheduler.java:406)
	at org.jobrunr.scheduling.JobScheduler.enqueue(JobScheduler.java:397)
	at org.jobrunr.scheduling.JobScheduler.enqueue(JobScheduler.java:79)
	at org.jobrunr.scheduling.BackgroundJob.enqueue(BackgroundJob.java:39)
	at be.es.eventsystem.calendar.CalendarService.createCalendarEntry(CalendarService.java:106)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 无法构造 `be.es.eventsystem.calendar.CalendarEntry` 的实例(没有默认构造函数等创建者):无法从对象值反序列化(没有委托或基于属性的创建者)
 在 [Source: (String)"{"version":0,"jobSignature":"CalendarService.createCalendarEntry(CalendarEntry)","jobName":"CalendarService.createCalendarEntry(be.es.eventsystem.calendar.CalendarEntry@ea7ae0ea)","jobDetails":{"className":"be.es.eventsystem.calendar.CalendarService","staticFieldName":null,"methodName":"createCalendarEntry","jobParameters":[{"className":"be.es.eventsystem.calendar.CalendarEntry","object":{"@class":"be.es.eventsystem.calendar.CalendarEntry","title":"Quatuor Ebène","eventDate":"2020-09-16T20:00:00Z","id":"bc8ad3db-cf89-49b6-a382-8b3a08c3cbd2"}}]},"id":"43a6e74a-4b53-4227-9985-4daf0005abc7","jobHist"[truncated 182 chars]; line: 1, column: 358](通过引用链:org.jobrunr.jobs.Job["jobDetails"]->org.jobrunr.jobs.JobDetails["jobParameters"]->java.util.ArrayList[0]->org.jobrunr.jobs.JobParameter["object"])
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1615)
	at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400)
	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1077)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1332)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:331)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:199)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:166)
英文:

We are using JobRunr to do some background job processing in Java.

We enqueue the jobs as follows:

CalendarEntry calendarEntry = new CalendarEntry("Quatuor Ebène", LocalDateTime.of(2020, 9, 16, 20, 0, 0).toInstant(ZoneOffset.UTC));
jobScheduler.enqueue(() -> calendarService.createCalendarEntry(calendarEntry));

When scheduling the job, we receive the following exception... any idea what is going on?

Did you register all necessary Jackson Modules?
org.jobrunr.JobRunrException: Did you register all necessary Jackson Modules?
	at org.jobrunr.JobRunrException.configurationException(JobRunrException.java:56)
	at org.jobrunr.utils.mapper.jackson.JacksonJsonMapper.deserialize(JacksonJsonMapper.java:76)
	at org.jobrunr.jobs.mappers.JobMapper.deserializeJob(JobMapper.java:20)
	at org.jobrunr.storage.InMemoryStorageProvider.deepClone(InMemoryStorageProvider.java:243)
	at org.jobrunr.storage.InMemoryStorageProvider.saveJob(InMemoryStorageProvider.java:259)
	at org.jobrunr.storage.InMemoryStorageProvider.save(InMemoryStorageProvider.java:109)
	at org.jobrunr.scheduling.JobScheduler.saveJob(JobScheduler.java:406)
	at org.jobrunr.scheduling.JobScheduler.enqueue(JobScheduler.java:397)
	at org.jobrunr.scheduling.JobScheduler.enqueue(JobScheduler.java:79)
	at org.jobrunr.scheduling.BackgroundJob.enqueue(BackgroundJob.java:39)
	at be.es.eventsystem.calendar.CalendarService.createCalendarEntry(CalendarService.java:106)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `be.es.eventsystem.calendar.CalendarEntry` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
 at [Source: (String)"{"version":0,"jobSignature":"CalendarService.createCalendarEntry(CalendarEntry)","jobName":"CalendarService.createCalendarEntry(be.es.eventsystem.calendar.CalendarEntry@ea7ae0ea)","jobDetails":{"className":"be.es.eventsystem.calendar.CalendarService","staticFieldName":null,"methodName":"createCalendarEntry","jobParameters":[{"className":"be.es.eventsystem.calendar.CalendarEntry","object":{"@class":"be.es.eventsystem.calendar.CalendarEntry","title":"Quatuor Ebène","eventDate":"2020-09-16T20:00:00Z","id":"bc8ad3db-cf89-49b6-a382-8b3a08c3cbd2"}}]},"id":"43a6e74a-4b53-4227-9985-4daf0005abc7","jobHist"[truncated 182 chars]; line: 1, column: 358] (through reference chain: org.jobrunr.jobs.Job["jobDetails"]->org.jobrunr.jobs.JobDetails["jobParameters"]->java.util.ArrayList[0]->org.jobrunr.jobs.JobParameter["object"])
	at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
	at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1615)
	at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:400)
	at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1077)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1332)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:331)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:199)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:166)

答案1

得分: 2

我认为原因是您的CalendarEntry类没有默认构造函数,而 Jackson 在尝试进行反序列化时需要这个构造函数。

英文:

I think the reason is that your CalendarEntry class does not have a default constructor, which is needed as Jackson will try to deserialize it.

huangapple
  • 本文由 发表于 2020年9月17日 16:43:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/63934401.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定