Skip to content

Commit

Permalink
refactor($quartz): create another instance instead of casting object
Browse files Browse the repository at this point in the history
java.lang.ClassCastException: class com.jmsoftware.maf.springcloudstarter.quartz.entity.persistence.QuartzJobConfiguration cannot be cast to class com.jmsoftware.maf.springcloudstarter.quartz.entity.persistence.QuartzJobConfiguration (com.jmsoftware.maf.springcloudstarter.quartz.entity.persistence.QuartzJobConfiguration is in unnamed module of loader 'app'; com.jmsoftware.maf.springcloudstarter.quartz.entity.persistence.QuartzJobConfiguration is in unnamed module of loader org.springframework.boot.devtools.restart.classloader.RestartClassLoader @28e47ab1)
	at com.jmsoftware.maf.springcloudstarter.quartz.job.AbstractQuartzJob.executeInternal(AbstractQuartzJob.java:30)
  • Loading branch information
johnnymillergh committed Apr 2, 2022
1 parent 901d768 commit 31cd72e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.jmsoftware.maf.springcloudstarter.quartz.entity.persistence;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jmsoftware.maf.springcloudstarter.database.BasePersistenceEntity;
import lombok.Data;
Expand Down Expand Up @@ -32,11 +30,6 @@ public class QuartzJobConfiguration extends BasePersistenceEntity implements Ser
public static final String COL_DESCRIPTION = "description";
public static final String COL_STATUS = "status";

/**
* The primary key ID
*/
@TableId(value = COL_ID, type = IdType.AUTO)
private Long id;
/**
* Name of job
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
*/
@Slf4j
abstract class AbstractQuartzJob extends QuartzJobBean {
private static final String QUARTZ_JOB_CONFIGURATION_CLASS = QuartzJobConfiguration.class.getName();

@Override
protected final void executeInternal(JobExecutionContext context) {
val sourceQuartzJobConfiguration = context.getMergedJobDataMap().get(QUARTZ_JOB_CONFIGURATION);
if (!(sourceQuartzJobConfiguration instanceof QuartzJobConfiguration)) {
if (!(QUARTZ_JOB_CONFIGURATION_CLASS.equals(sourceQuartzJobConfiguration.getClass().getName()))) {
throw new IllegalArgumentException(
"Invalid job data! Not the instance of QuartzJobConfiguration. Runtime actual class: "
+ sourceQuartzJobConfiguration.getClass());
}
if (log.isDebugEnabled()) {
log.debug("Found and QuartzJobConfiguration from job data map: {}", sourceQuartzJobConfiguration);
}
val quartzJobConfiguration = new QuartzJobConfiguration();
BeanUtil.copyProperties(sourceQuartzJobConfiguration, quartzJobConfiguration);
try {
this.invoke(context, (QuartzJobConfiguration) sourceQuartzJobConfiguration);
this.invoke(context, quartzJobConfiguration);
} catch (Exception e) {
log.error("Exception occurred when invoking method", e);
}
Expand Down

0 comments on commit 31cd72e

Please sign in to comment.