Spring cloud alibaba dubbo + nacos 整合报错 Error creating bean with name ‘feignTargeter‘解决办法

完整报错信息如下

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘feignTargeter’ defined in class path resource [org/springframework/cloud/openfeign/FeignAutoConfiguration D e f a u l t F e i g n T a r g e t e r C o n f i g u r a t i o n . c l a s s ] : I n i t i a l i z a t i o n o f b e a n f a i l e d ; n e s t e d e x c e p t i o n i s j a v a . l a n g . I l l e g a l A c c e s s E r r o r : c l a s s o r g . s p r i n g f r a m e w o r k . c l o u d . o p e n f e i g n . DefaultFeignTargeterConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalAccessError: class org.springframework.cloud.openfeign. DefaultFeignTargeterConfiguration.class]:Initializationofbeanfailed;nestedexceptionisjava.lang.IllegalAccessError:classorg.springframework.cloud.openfeign.Proxy79 cannot access its superinterface org.springframework.cloud.openfeign.Targeter
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:602) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean 0 ( A b s t r a c t B e a n F a c t o r y . j a v a : 324 )   [ s p r i n g − b e a n s − 5.2.12. R E L E A S E . j a r : 5.2.12. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t S i n g l e t o n B e a n R e g i s t r y . g e t S i n g l e t o n ( D e f a u l t S i n g l e t o n B e a n R e g i s t r y . j a v a : 234 )   [ s p r i n g − b e a n s − 5.2.12. R E L E A S E . j a r : 5.2.12. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . d o G e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 322 )   [ s p r i n g − b e a n s − 5.2.12. R E L E A S E . j a r : 5.2.12. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . A b s t r a c t B e a n F a c t o r y . g e t B e a n ( A b s t r a c t B e a n F a c t o r y . j a v a : 202 )   [ s p r i n g − b e a n s − 5.2.12. R E L E A S E . j a r : 5.2.12. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b e a n s . f a c t o r y . s u p p o r t . D e f a u l t L i s t a b l e B e a n F a c t o r y . p r e I n s t a n t i a t e S i n g l e t o n s ( D e f a u l t L i s t a b l e B e a n F a c t o r y . j a v a : 897 )   [ s p r i n g − b e a n s − 5.2.12. R E L E A S E . j a r : 5.2.12. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . s u p p o r t . A b s t r a c t A p p l i c a t i o n C o n t e x t . f i n i s h B e a n F a c t o r y I n i t i a l i z a t i o n ( A b s t r a c t A p p l i c a t i o n C o n t e x t . j a v a : 879 )   [ s p r i n g − c o n t e x t − 5.2.12. R E L E A S E . j a r : 5.2.12. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . c o n t e x t . s u p p o r t . A b s t r a c t A p p l i c a t i o n C o n t e x t . r e f r e s h ( A b s t r a c t A p p l i c a t i o n C o n t e x t . j a v a : 551 )   [ s p r i n g − c o n t e x t − 5.2.12. R E L E A S E . j a r : 5.2.12. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r e f r e s h ( S p r i n g A p p l i c a t i o n . j a v a : 758 ) [ s p r i n g − b o o t − 2.3.7. R E L E A S E . j a r : 2.3.7. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r e f r e s h ( S p r i n g A p p l i c a t i o n . j a v a : 750 ) [ s p r i n g − b o o t − 2.3.7. R E L E A S E . j a r : 2.3.7. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r e f r e s h C o n t e x t ( S p r i n g A p p l i c a t i o n . j a v a : 405 ) [ s p r i n g − b o o t − 2.3.7. R E L E A S E . j a r : 2.3.7. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r u n ( S p r i n g A p p l i c a t i o n . j a v a : 315 ) [ s p r i n g − b o o t − 2.3.7. R E L E A S E . j a r : 2.3.7. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r u n ( S p r i n g A p p l i c a t i o n . j a v a : 1237 ) [ s p r i n g − b o o t − 2.3.7. R E L E A S E . j a r : 2.3.7. R E L E A S E ] a t o r g . s p r i n g f r a m e w o r k . b o o t . S p r i n g A p p l i c a t i o n . r u n ( S p r i n g A p p l i c a t i o n . j a v a : 1226 ) [ s p r i n g − b o o t − 2.3.7. R E L E A S E . j a r : 2.3.7. R E L E A S E ] a t c o m . e x a m p l e . d u b b o p r o v i d e r . D u b b o P r o v i d e r A p p l i c a t i o n . m a i n ( D u b b o P r o v i d e r A p p l i c a t i o n . j a v a : 12 ) [ c l a s s e s / : n a ] a t s u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d )   [ n a : 1.8. 0 1 61 ] a t s u n . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 62 )   [ n a : 1.8. 0 1 61 ] a t s u n . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( D e l e g a t i n g M e t h o d A c c e s s o r I m p l . j a v a : 43 )   [ n a : 1.8. 0 1 61 ] a t j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( M e t h o d . j a v a : 498 )   [ n a : 1.8. 0 1 61 ] a t o r g . s p r i n g f r a m e w o r k . b o o t . d e v t o o l s . r e s t a r t . R e s t a r t L a u n c h e r . r u n ( R e s t a r t L a u n c h e r . j a v a : 49 ) [ s p r i n g − b o o t − d e v t o o l s − 2.3.7. R E L E A S E . j a r : 2.3.7. R E L E A S E ] C a u s e d b y : j a v a . l a n g . I l l e g a l A c c e s s E r r o r : c l a s s o r g . s p r i n g f r a m e w o r k . c l o u d . o p e n f e i g n . 0(AbstractBeanFactory.java:324) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE] at com.example.dubboprovider.DubboProviderApplication.main(DubboProviderApplication.java:12) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_161] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_161] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_161] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_161] at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.3.7.RELEASE.jar:2.3.7.RELEASE] Caused by: java.lang.IllegalAccessError: class org.springframework.cloud.openfeign. 0(AbstractBeanFactory.java:324) [springbeans5.2.12.RELEASE.jar:5.2.12.RELEASE]atorg.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) [springbeans5.2.12.RELEASE.jar:5.2.12.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) [springbeans5.2.12.RELEASE.jar:5.2.12.RELEASE]atorg.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [springbeans5.2.12.RELEASE.jar:5.2.12.RELEASE]atorg.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) [springbeans5.2.12.RELEASE.jar:5.2.12.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) [springcontext5.2.12.RELEASE.jar:5.2.12.RELEASE]atorg.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [springcontext5.2.12.RELEASE.jar:5.2.12.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)[springboot2.3.7.RELEASE.jar:2.3.7.RELEASE]atorg.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)[springboot2.3.7.RELEASE.jar:2.3.7.RELEASE]atorg.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405)[springboot2.3.7.RELEASE.jar:2.3.7.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:315)[springboot2.3.7.RELEASE.jar:2.3.7.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1237)[springboot2.3.7.RELEASE.jar:2.3.7.RELEASE]atorg.springframework.boot.SpringApplication.run(SpringApplication.java:1226)[springboot2.3.7.RELEASE.jar:2.3.7.RELEASE]atcom.example.dubboprovider.DubboProviderApplication.main(DubboProviderApplication.java:12)[classes/:na]atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) [na:1.8.0161]atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [na:1.8.0161]atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [na:1.8.0161]atjava.lang.reflect.Method.invoke(Method.java:498) [na:1.8.0161]atorg.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[springbootdevtools2.3.7.RELEASE.jar:2.3.7.RELEASE]Causedby:java.lang.IllegalAccessError:classorg.springframework.cloud.openfeign.Proxy79 cannot access its superinterface org.springframework.cloud.openfeign.Targeter
at java.lang.reflect.Proxy.defineClass0(Native Method) ~[na:1.8.0_161]
at java.lang.reflect.Proxy.access 300 ( P r o x y . j a v a : 228 )   [ n a : 1.8. 0 1 61 ] a t j a v a . l a n g . r e f l e c t . P r o x y 300(Proxy.java:228) ~[na:1.8.0_161] at java.lang.reflect.Proxy 300(Proxy.java:228) [na:1.8.0161]atjava.lang.reflect.ProxyProxyClassFactory.apply(Proxy.java:642) ~[na:1.8.0_161]
at java.lang.reflect.Proxy P r o x y C l a s s F a c t o r y . a p p l y ( P r o x y . j a v a : 557 )   [ n a : 1.8. 0 1 61 ] a t j a v a . l a n g . r e f l e c t . W e a k C a c h e ProxyClassFactory.apply(Proxy.java:557) ~[na:1.8.0_161] at java.lang.reflect.WeakCache ProxyClassFactory.apply(Proxy.java:557) [na:1.8.0161]atjava.lang.reflect.WeakCacheFactory.get(WeakCache.java:230) ~[na:1.8.0_161]
at java.lang.reflect.WeakCache.get(WeakCache.java:127) ~[na:1.8.0_161]
at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419) ~[na:1.8.0_161]
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719) ~[na:1.8.0_161]
at com.alibaba.cloud.dubbo.openfeign.TargeterBeanPostProcessor.postProcessAfterInitialization(TargeterBeanPostProcessor.java:75) ~[spring-cloud-starter-dubbo-2.2.2.RELEASE.jar:2.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:430) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1798) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
… 20 common frames omitted

解决办法: 去掉springboot devtools热启动包,依赖冲突导致的。

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

版本冲突和依赖冲突往往折磨人

如果要保留热启动包则拦截bean修改TargeterBeanPostProcessor.postProcessAfterInitialization方法

public Object postProcessAfterInitialization(final Object bean, String beanName) throws BeansException {
        if (ClassUtils.isPresent("org.springframework.cloud.openfeign.Targeter", this.classLoader)) {
            Class<?> beanClass = ClassUtils.getUserClass(bean.getClass());
            Class<?> targetClass = ClassUtils.resolveClassName("org.springframework.cloud.openfeign.Targeter", this.classLoader);
            if (targetClass.isAssignableFrom(beanClass)) {
                return Proxy.newProxyInstance(beanClass.getClassLoader(), new Class[]{targetClass}, new TargeterInvocationHandler(bean, this.environment, beanClass.getClassLoader(), this.dubboServiceMetadataRepository, this.dubboGenericServiceFactory, this.contextFactory));
            }
        }
 
        return bean;
    }
posted @ 2021-10-13 15:05  HumorChen99  阅读(23)  评论(0编辑  收藏  举报  来源