dubbo java.lang.ClassCastException: java.lang.String cannot be cast to java.lan
程序员文章站
2022-07-07 17:39:21
...
dubbo java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Class
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xxxxxController': Injection of @DubboReference dependencies is failed; nested exception is java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Class at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:183) ~[spring-context-support-1.0.11.jar:?] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1425) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar:5.2.8.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.2.RELEASE.jar:2.3.2.RELEASE] at com.echovin.demo.visit.VisitWebApplication.main(VisitWebApplication.java:12) [main/:?] Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Class at org.apache.dubbo.config.spring.util.DubboAnnotationUtils.resolveServiceInterfaceClass(DubboAnnotationUtils.java:95) ~[dubbo-2.7.8.jar:2.7.8] at org.apache.dubbo.config.spring.util.DubboAnnotationUtils.resolveInterfaceName(DubboAnnotationUtils.java:78) ~[dubbo-2.7.8.jar:2.7.8] at org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilder.<init>(ServiceBeanNameBuilder.java:65) ~[dubbo-2.7.8.jar:2.7.8] at org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilder.create(ServiceBeanNameBuilder.java:78) ~[dubbo-2.7.8.jar:2.7.8] at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildReferencedBeanName(ReferenceAnnotationBeanPostProcessor.java:303) ~[dubbo-2.7.8.jar:2.7.8] at org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInjectedObjectCacheKey(ReferenceAnnotationBeanPostProcessor.java:292) ~[dubbo-2.7.8.jar:2.7.8] at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.getInjectedObject(AbstractAnnotationBeanPostProcessor.java:404) ~[spring-context-support-1.0.11.jar:?] at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor$AnnotatedFieldElement.inject(AbstractAnnotationBeanPostProcessor.java:626) ~[spring-context-support-1.0.11.jar:?] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE] at com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor.postProcessPropertyValues(AbstractAnnotationBeanPostProcessor.java:179) ~[spring-context-support-1.0.11.jar:?] ... 18 more
参考: https://github.com/apache/dubbo/issues/7115
解决办法:
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-dubbo</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>
依赖的spring-context-support版本要对应,过高或过低版本,将导致上面的错误
<dependency> <groupId>com.alibaba.spring</groupId> <artifactId>spring-context-support</artifactId> <version>${alibaba_spring_context_support_version}</version>--> </dependency>
推荐阅读
-
dubbo java.lang.ClassCastException: java.lang.String cannot be cast to java.lan
-
dubbo java.lang.ClassCastException: java.lang.String cannot be cast to java.lan
-
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page
-
整合SSH java.lang.ClassCastException: xxx_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
-
java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
-
java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to xxx 类型转换异常
-
org.springframework.boot.actuate.endpoint.EndpointId cannot be cast to java.lang.String 异常处理
-
Redis 服务器没有启动导致的错误:java.lang.ClassCastException: [B cannot be cast to java.lang.Long
-
java.lang.ClassCastException: com.sun.proxy.$Proxy$ cannot be cast to ...
-
java.lang.ClassCastException: com.alibaba.fastjson.JSONObject cannot be cast to