java.lang.ClassCastException 同包同类名强转异常

目录

问题

今天碰到了一个很诡异的问题,有一段代码在执行强转时居然提示自己不能转自己,还真的是头一回碰到这种问题,代码及异常如下

ComplexOrderDbShardingAlgorithm complexOrderDbShardingAlgorithm = (ComplexOrderDbShardingAlgorithm) ReflectUtil.getFieldValue(dataBaseShardingStrategy, "shardingAlgorithm");
complexOrderDbShardingAlgorithm.init(tbShardingConfigServiceImpl);
Caused by: java.lang.ClassCastException: com.chinawu.cloud.ss.config.sharding.ComplexOrderDbShardingAlgorithm cannot be cast to com.chinawu.cloud.ss.config.sharding.ComplexOrderDbShardingAlgorithm
	at com.chinawu.cloud.ss.config.sharding.StartupConfig.loadLogInit(StartupConfig.java:57) ~[classes/:na]
	at com.chinawu.cloud.ss.config.sharding.StartupConfig.init(StartupConfig.java:39) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
	... 23 common frames omitted

解决

问题太不可思议了,业务代码原先本地调试都正常的,怎么就出现该问题了呢?
排查后发现项目pom中原本注释的springboot 热部署依赖这次因为有个业务需要调试就直接打开了,结果就导致了本次强转的问题。

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

注释后重新测试了下,果然世界舒畅了。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值