SpringCloud Greenwich(六)集成dubbo与openfeign的feignTargeter报错,cannot access its superinterface Targeter

一、现象

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignTargeter' defined in class path resource [org/springframework/cloud/openfeign/FeignAutoConfiguration$HystrixFeignTargeterConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalAccessError: class org.springframework.cloud.openfeign.$Proxy109 cannot access its superinterface org.springframework.cloud.openfeign.Targeter

at com.alibaba.cloud.dubbo.openfeign.TargeterBeanPostProcessor.postProcessAfterInitialization(TargeterBeanPostProcessor.java:75)

原始日志:

2021-02-09 00:02:23,908 ERROR [restartedMain] 14833 org.springframework.boot.SpringApplication[823]: Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignTargeter' defined in class path resource [org/springframework/cloud/openfeign/FeignAutoConfiguration$HystrixFeignTargeterConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalAccessError: class org.springframework.cloud.openfeign.$Proxy109 cannot access its superinterface org.springframework.cloud.openfeign.Targeterat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$146/410686727.getObject(Unknown Source)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:847)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)at com.mk.springcloud.dubbo.provider.UserProviderApplication.main(UserProviderApplication.java:13)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:497)at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalAccessError: class org.springframework.cloud.openfeign.$Proxy109 cannot access its superinterface org.springframework.cloud.openfeign.Targeterat java.lang.reflect.Proxy.defineClass0(Native Method)at java.lang.reflect.Proxy.access$300(Proxy.java:228)at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:642)at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:557)at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:230)at java.lang.reflect.WeakCache.get(WeakCache.java:127)at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:419)at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:719)at com.alibaba.cloud.dubbo.openfeign.TargeterBeanPostProcessor.postProcessAfterInitialization(TargeterBeanPostProcessor.java:75)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:429)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)... 21 common frames omitted

(1)maven设置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.1.9.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.mk.springcloud</groupId><artifactId>springcloud-nacos-dubbo</artifactId><version>1.0.0</version><packaging>pom</packaging><properties><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><version>2.1.3.RELEASE</version></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId><version>2.1.3.RELEASE</version></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>2.1.3.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><modules><module>dubbo-interface</module><module>user-provider</module><module>class-provider</module><module>dubbo-consumer</module><module>micro-service</module><module>zuul-gateway</module><module>springcloud-gateway</module></modules><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>

(2)FeignAutoConfiguration的feignTargeter创建类

@Configuration
@ConditionalOnClass({Feign.class})
@EnableConfigurationProperties({FeignClientProperties.class, FeignHttpClientProperties.class})
public class FeignAutoConfiguration {@Configuration@ConditionalOnClass(name = {"feign.hystrix.HystrixFeign"})protected static class HystrixFeignTargeterConfiguration {protected HystrixFeignTargeterConfiguration() {}@Bean@ConditionalOnMissingBeanpublic Targeter feignTargeter() {return new HystrixTargeter();}}
}

(3)TargeterBeanPostProcessor.postProcessAfterInitialization方法

public class TargeterBeanPostProcessor implements BeanPostProcessor, BeanClassLoaderAware {private final Environment environment;private final DubboServiceMetadataRepository dubboServiceMetadataRepository;private final DubboGenericServiceFactory dubboGenericServiceFactory;private final DubboGenericServiceExecutionContextFactory contextFactory;private ClassLoader classLoader;public TargeterBeanPostProcessor(Environment environment, DubboServiceMetadataRepository dubboServiceMetadataRepository, DubboGenericServiceFactory dubboGenericServiceFactory, DubboGenericServiceExecutionContextFactory contextFactory) {this.environment = environment;this.dubboServiceMetadataRepository = dubboServiceMetadataRepository;this.dubboGenericServiceFactory = dubboGenericServiceFactory;this.contextFactory = contextFactory;}public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {return bean;}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(this.classLoader, new Class[]{targetClass}, new TargeterInvocationHandler(bean, this.environment, this.classLoader, this.dubboServiceMetadataRepository, this.dubboGenericServiceFactory, this.contextFactory));}}return bean;}public void setBeanClassLoader(ClassLoader classLoader) {this.classLoader = classLoader;}
}

 

二、分析原因

(1)排除openfeign-core依赖包和spring-cloud-starter-openfeign启动正常

<dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-dubbo</artifactId><version>2.1.3.RELEASE</version><exclusions><exclusion><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-openfeign-core</artifactId></exclusion></exclusions>
</dependency><!--<dependency>--><!--<groupId>org.springframework.cloud</groupId>--><!--<artifactId>spring-cloud-starter-openfeign</artifactId>--><!--<version>2.1.3.RELEASE</version>-->
<!--</dependency>-->

(2)SpringBootApplication排除FeignAutoConfiguration也启动正常

@EnableDiscoveryClient
@SpringBootApplication(exclude = FeignAutoConfiguration.class)
public class UserProviderApplication {public static void main(String[] args) {SpringApplication.run(UserProviderApplication.class, args);}}

(3)debug发现beanClass.getClassLoader()和classLoader不一致造成类访问不了

(4)找出起因

看到RestartClassLoader就猜想到IDEA的agent和springboot的热发布,从classLoader对象找到了包信息。如下:

ProtectionDomain  (null <no signer certificates>)
 org.springframework.boot.devtools.restart.classloader.RestartClassLoader@bc8c9ff

是springboot的热发布包造成的,去掉spring-boot-devtools则能够正常启动。

(5)拓展

官方说明 官方文档 :

By default, any open project in your IDE will be loaded using the “restart” classloader, and any regular .jar file will be loaded using the “base” classloader. If you work on a multi-module project, and not each module is imported into your IDE, you may need to customize things. To do this you can create a META-INF/spring-devtools.properties file.

翻译:

默认情况下,IDE中打开的项目文件都会使用devtools的restart加载器,但是三方的jar文件则会被系统默认的加载器加载。如果你涉及多模块开发的时候需要把每一个模块在IDE打开,你需要指定加载器的时候,在META/INF下创建一个spring-devtools.properties。

 

三、解决方法

(1)去掉热部署包spring-boot-devtools

(2)拦截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;}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/322114.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一个开源的强类型客户端(.NET 中的 Open Fegin)— Rabbit Go

在做RabbitCloud&#xff08;之前是一个RPC&#xff0c;现在是一个微服务框架&#xff09;的时候往往避不开客户端代理&#xff0c;之前把这些客户端代理都算作服务框架不可缺少的一部分&#xff0c;随着后期的深入发现这些客户端代理其实可以互通&#xff0c;类似spring cloud…

SpringCloud Greenwich(七)集成dubbo先启动消费者(check=false),然后启动提供者无法自动发现注册

SpringCloud Greenwich集成dubbo先启动消费者&#xff08;checkfalse&#xff09;&#xff0c;然后启动提供者无法自动发现注册问题。 官方说明&#xff1a;修复bug的提交时间 spring-cloud-starter-dubbo 2.2.4.RELEASE之前的版本都会有先启动消费者&#xff08;checkfalse&am…

.NET Core 实现定时抓取博客园首页文章信息并发送到邮箱

前言大家好&#xff0c;我是晓晨。许久没有更新博客了&#xff0c;今天给大家带来一篇干货型文章&#xff0c;一个每隔5分钟抓取博客园首页文章信息并在第二天的上午9点发送到你的邮箱的小工具。比如我在2018年2月14日&#xff0c;9点来到公司我就会收到一封邮件&#xff0c;是…

Linux shell echo打印不出换行

一、现象 echo打印不出换行 指令 ps aux | grep python ps aux | grep python | xargs echo 运行结果&#xff1a; 二、使用参数-e echo一样打印不出换行 ps aux | grep python | xargs echo -e 运行结果&#xff1a; 三、使用参数-e和双引号包裹占位符 echo终于可以…

基于Citus和ASP.NET Core开发多租户应用

Citus是基于PsotgreSQL的扩展&#xff0c;用于切分PsotgreSQL的数据&#xff0c;非常简单地实现数据“切片&#xff08;sharp&#xff09;”。如果不使用Citus&#xff0c;则需要开发者自己实现分布式数据访问层&#xff08;DDAL&#xff09;&#xff0c;实现路由和结果汇总等逻…

ASP.NET CORE 微服务(简化版)实战系列-没有比这性价比再高的实战课程了

ASP.NET CORE 微服务(简化版&#xff09;实战系列&#xff0c;最后1天298&#xff0c;现在注册购买再减50。作者jesse 腾飞在2.14 早上我买了他的课程后&#xff0c;他才做了下面这个活动&#xff1a;作者jesse 腾飞花了大量的时间做了一个非常好的视频教程&#xff0c;我个人也…

祝大家狗年家庭事业旺旺旺

冒泡排序&#xff0c;选择排序&#xff0c;插入排序&#xff0c;快速排序&#xff0c;堆排序&#xff0c;归并排序&#xff0c;希尔排序&#xff0c;桶排序&#xff0c;基数排序新年帮您排忧解难。有向图&#xff0c;无向图&#xff0c;有环图&#xff0c;无环图&#xff0c;完…

携程Apollo(阿波罗)配置中心在.NET Core项目快速集成

.NET Core的支持文档大体上可以参考文档.Net客户端使用指南&#xff1a;https://github.com/ctripcorp/apollo/wiki/.Net%E5%AE%A2%E6%88%B7%E7%AB%AF%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97登录Apollo上新建App和相关的配置项&#xff0c;可以参考如下配置&#xff1a;在Nuget上…

欢乐纪中A组赛【2019.8.9】

前言 在短暂的比赛时间中&#xff0c;我发现本菜鸡越是功于心计想ACACAC&#xff0c;越是拿不到分&#xff0c;所以。。。 我不写比赛了JOJO!JOJO!JOJO! 成绩 JJJ表示初中&#xff0c;HHH表示高中后面加的是几年级 RankRankRankPersonPersonPersonScoreScoreScoreAAABBBCCC17…

SpringCloud Zuul(四)之工作原理

一、筛选器概述 Zuul的中心是一系列过滤器&#xff0c;这些过滤器能够在HTTP请求和响应的路由期间执行一系列操作。 以下是Zuul过滤器的主要特征&#xff1a; 类型&#xff1a;通常定义路由流程中应用过滤器的阶段&#xff08;尽管它可以是任何自定义字符串&#xff09;执行…

使用Nito.AsyncEx实现异步锁

Lock是常用的同步锁&#xff0c;但是我们无法在Lock的内部实现异步调用&#xff0c;比如我们无法使用await.以下面的代码为例&#xff0c;当你在lock内部使用await时&#xff0c;VS会报错提醒。最简单的解决办法就是使用第三方的库Nito.AsyncEx。可以通过Nuget安装。通过AsyncL…

汽车之家店铺数据抓取 DotnetSpider实战[一]

一、背景春节也不能闲着&#xff0c;一直想学一下爬虫怎么玩&#xff0c;网上搜了一大堆&#xff0c;大多都是Python的&#xff0c;大家也比较活跃&#xff0c;文章也比较多&#xff0c;找了一圈&#xff0c;发现园子里面有个大神开发了一个DotNetSpider的开源库&#xff0c;很…

Comet OJ(Contest #8)-D菜菜种菜【树状数组,指针】

前言 话说昨晚写题的时候贼NMNMNM惊险&#xff0c;最后22秒把程序交了上去竟然过了 正题 题目链接:https://cometoj.com/contest/58/problem/D?problem_id2758 题目大意 nnn个点mmm条单向边&#xff0c;然后每次询问一个区间[L,R][L,R][L,R]求若只选择这个区间的点&#xf…

微软正式开源Blazor ,将.NET带回到浏览器

微软 ASP.NET 团队近日正式开源了 Blazor &#xff0c;这是一个 Web UI 框架&#xff0c;可通过 WebAssembly 在任意浏览器中运行 .Net 。Blazor 旨在简化快速的单页面 .Net 浏览器应用的构建过程&#xff0c;它虽然使用了诸如 CSS 和 HTML 之类的 Web 技术&#xff0c;但它使…

在.NetCore中使用Myrmec检测文件真实格式

Myrmec 是什么&#xff1f;Myrmec 是一个用于检测文件格式的库&#xff0c;Myrmec不同于其它库或者手写检测代码&#xff0c;Myrmec不依赖文件扩展名&#xff08;在实际使用中&#xff0c;你的用户很可能使用虚假的扩展名欺骗你的应用程序&#xff09;&#xff0c;Myrmec会检测…

jzoj3736-[NOI2014模拟7.11]数学题(math)【计算几何】

正题 题目大意 给定两个向量a(x1,y1),b(x2,y2)a(x_1,y_1),b(x_2,y_2)a(x1​,y1​),b(x2​,y2​)&#xff0c;然后求∣λ1aλ2b∣|\lambda _1a\lambda _2b|∣λ1​aλ2​b∣的最小值&#xff0c;要求λ1,λ2\lambda_1,\lambda _2λ1​,λ2​不同时为0。 解题思路 我们先考虑若…

Orleans之EventSourcing

引入:如果没有意外,我再这篇文章中用ES代替EventSourcing,如果碰到"事件回溯","事件溯源","事溯"等词语,都一般代表Eventsourcing.如果引入Orleans而不用es的话,那就只用了Orleans一半的优点,多线程编程的逻辑\排错的简化以及可分布式.下面我聊聊…

Alex: 2018年对混合现实MR的展望

原文作者&#xff1a;Alex Kipman&#xff0c; 微软操作系统工程院技术院士 Hello 大家好&#xff01;难以置信我们已经走过了2018年的头两个月了。每年一月份我都会去巴西省亲&#xff0c;和我的家人欢聚一堂&#xff0c;度过一个美好的假日。在我省亲的同时&#xff0c;我想了…

jzoj3738-[NOI2014模拟7.11]理想城市(city)【树,模型转换】

正题 题目大意 一个理想城市有nnn个块构成&#xff0c;有以下性质 任意两个块之间可以通过其他块到达任意两个块之间可以不通过其他块(通过空位)到达 然后求每个块之间的距离之和。 解题思路 我们将横竖的距离分开计算。 假设现在我们考虑计算竖向的边的距离&#xff0c;我…

SpringCloud Ribbon(二)之自定义负载均衡策略IRule

一、Ribbon负载均衡策略 一个服务对应一个LoadBalancer&#xff0c;一个LoadBalancer只有一个Rule&#xff0c;LoadBalancer记录服务的注册地址&#xff0c;Rule提供从服务的注册地址中找出一个地址的规则。 Ribbon提供七种负载均衡策略&#xff0c;默认的负载均衡策略是轮训策…