zoukankan      html  css  js  c++  java
  • Quarts 执行定时任务失败(.job.entity.ScheduleJobEntity cannot be cast to com.)

    1、工作中通过Quarts执行定时任务,启动时报类型转换错误,就比较纳闷,同一个包怎么会转换失败。

    java.lang.ClassCastException: com.bodata.svc.modules.job.entity.ScheduleJobEntity cannot be cast to com.bodata.svc.modules.job.entity.ScheduleJobEntity
    	at com.bodata.svc.modules.job.utils.ScheduleJob.executeInternal(ScheduleJob.java:33)
    	at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75)
    	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
    
    2021-06-12 23:56:55.086 ERROR 20864 --- [eduler_Worker-1] org.quartz.core.ErrorLogger              : Job (DEFAULT.TASK_1234111111111111111 threw an exception.
    
    org.quartz.SchedulerException: Job threw an unhandled exception.
    	at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
    	at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
    Caused by: java.lang.ClassCastException: com.bodata.svc.modules.job.entity.ScheduleJobEntity cannot be cast to com.bodata.svc.modules.job.entity.ScheduleJobEntity
    	at com.bodata.svc.modules.job.utils.ScheduleJob.executeInternal(ScheduleJob.java:33)
    	at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75)
    	at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
    	... 1 common frames omitted
    

    2、通过网上查找,发现是热部署惹的祸。

    在pom文件中注释掉一下代码即可:

    <!--<dependency>
    <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
    </dependency>-->

    JVM判断两个类对象是否相同的依据:一是类全称;一个是类加载器,既然不是类名的问题,那肯定就是类加载器不同导致的。

    spring-boot-devtools会检测类路径的变化,当类路径内容发生变化后会自动重启应用程序。Spring Boot的重启技术通过使用两个类加载器。由于使用的是双类加载机制重启会非常快,如果启动较慢也可使用JRebel重加载技术。

    (1)base classloader (Base类加载器):加载不改变的Class,如第三方提供的jar包。

    (2)restart classloader(Restart类加载器):加载正在开发的Class。

  • 相关阅读:
    spring boot的@RequestParam和@RequestBody的区别
    SpringBoot 中常用注解@PathVaribale/@RequestParam/@GetMapping介绍
    Required String parameter is not present
    Spring Boot 日志记录 SLF4J
    400错误,Required String parameter 'paramter' is not present
    初学 Spring boot 报错 Whitelabel Error Page 404
    Powershell获取WMI设备清单
    Powershell快速入门
    perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志
    制作Windows10政府版的小白教程
  • 原文地址:https://www.cnblogs.com/lansetuerqi/p/14879391.html
Copyright © 2011-2022 走看看