定时任务问题

提问 已结 5 150
靖大大
靖大大 VIP1 2019-06-04
悬赏:30积分
版本:renren-fast 2.0 浏览器:
io.renren.modules.job.entity.ScheduleJobEntity cannot be cast to io.renren.modules.job.entity.ScheduleJobEntity 这个错误..什么鬼.. 俩个相同的类型 强转出错? 刚看到大佬的回复 激动的结贴了..然后 ... 注释掉了热部署 还是有这问题... 大佬 求助啊..
回帖
  • 这个确实是热部署的问题,确保spring-boot-devtools注释掉了,因为会有2个类加载器,导致不能强转
    0
  • 靖大大
    2019-06-05
    @Mark 大佬 我确定 已经注释掉了这个...
    0
  • 靖大大
    2019-06-05
    java.lang.ClassCastException: io.renren.modules.job.entity.ScheduleJobEntity cannot be cast to io.renren.modules.job.entity.ScheduleJobEntity at io.renren.modules.job.utils.ScheduleJob.executeInternal(ScheduleJob.java:50) 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) 2019-06-05 10:38:20.658 ERROR 1615 --- [eduler_Worker-1] org.quartz.core.ErrorLogger : Job (DEFAULT.TASK_15 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: io.renren.modules.job.entity.ScheduleJobEntity cannot be cast to io.renren.modules.job.entity.ScheduleJobEntity at io.renren.modules.job.utils.ScheduleJob.executeInternal(ScheduleJob.java:50) at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ... 1 common frames omitted 附上错误信息
    0
  • @靖大大 包名都是一样的,确实是因为多个类加载器造成的,如果找不到解决办法,就先通过json转换吧,别使用类强转了,后面我们把这块的逻辑修改一下
    0
  • 靖大大
    2019-06-05
    这是2.0 版本的 3.0 还没发现这错误 打扰啦大佬 我用javaBean 强转 可行 face[ok] 好像还有别人遇到这问题..我把方法粘下来 public class JavaBeanUtil { private static Logger logger = LoggerFactory.getLogger(JavaBeanUtil.class); /** *  * 实体类转map *  * @param obj *  * @return *   */ public static Map<String, Object> convertBeanToMap(Object obj) { if (obj == null) { return null; } Map<String, Object> map = new HashMap<String, Object>(); try { BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor property : propertyDescriptors) { String key = property.getName(); // 过滤class属性 if (!key.equals("class")) { // 得到property对应的getter方法 Method getter = property.getReadMethod(); Object value = getter.invoke(obj); if (null == value) { map.put(key, ""); } else { map.put(key, value); } } } } catch (Exception e) { logger.error("convertBean2Map Error {}", e); } return map; } /**      * map 转实体类      * @param clazz      * @param map      * @param <T>      * @return      */ public static <T> T convertMapToBean(Class<T> clazz, Map<String,Object> map) { T obj = null; try { BeanInfo beanInfo = Introspector.getBeanInfo(clazz); obj = clazz.newInstance(); // 创建 JavaBean 对象 // 给 JavaBean 对象的属性赋值 PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); for (int i = 0; i < propertyDescriptors.length; i++) { PropertyDescriptor descriptor = propertyDescriptors[i]; String propertyName = descriptor.getName(); if (map.containsKey(propertyName)) { // 下面一句可以 try 起来,这样当一个属性赋值失败的时候就不会影响其他属性赋值。 Object value = map.get(propertyName); if ("".equals(value)) { value = null; } Object[] args = new Object[1]; args[0] = value; descriptor.getWriteMethod().invoke(obj, args); } } } catch (IllegalAccessException e) { logger.error("convertMapToBean 实例化JavaBean失败 Error{}" ,e); } catch (IntrospectionException e) { logger.error("convertMapToBean 分析类属性失败 Error{}" ,e); } catch (IllegalArgumentException e) { logger.error("convertMapToBean 映射错误 Error{}" ,e); } catch (InstantiationException e) { logger.error("convertMapToBean 实例化 JavaBean 失败 Error{}" ,e); }catch (InvocationTargetException e){ logger.error("convertMapToBean字段映射失败 Error{}" ,e); }catch (Exception e){ logger.error("convertMapToBean Error{}" ,e); } return (T) obj; } }
    0
本帖已结贴