千家信息网

OpenJDK11与Spring Cloud Finchley的不兼容问题与解决方法

发表于:2025-02-06 作者:千家信息网编辑
千家信息网最后更新 2025年02月06日,本篇内容主要讲解"OpenJDK11与Spring Cloud Finchley的不兼容问题与解决方法",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"Ope
千家信息网最后更新 2025年02月06日OpenJDK11与Spring Cloud Finchley的不兼容问题与解决方法

本篇内容主要讲解"OpenJDK11与Spring Cloud Finchley的不兼容问题与解决方法",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"OpenJDK11与Spring Cloud Finchley的不兼容问题与解决方法"吧!

本文的环境:OpenJDK 11.0.4,Spring Cloud finchley SR4,Spring Boot 2.0.3

最近遇到了一个问题,在feign调用的时候,时常会出现这样一个奇怪的错误:

2019-10-07 08:00:00.620 ERROR [xxx,e1ba4c7540954aa3,871b99c4576d42e3] [24] [XNIO-2 task-286][xxx:83]: URI:[/xxx], method:[PUT], 500Exception: class com.netflix.hystrix.exception.HystrixRuntimeException, xxxxx#xxxx(xxx) failed and no fallback available.com.netflix.hystrix.exception.HystrixRuntimeException: xxxxx#xxxx(xxx)  failed and no fallback available.        at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:822) ~[hystrix-core-1.5.18.jar!/:1.5.18]        at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:807) ~[hystrix-core-1.5.18.jar!/:1.5.18]        at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140) ~[rxjava-1.3.8.jar!/:1.3.8]省略无用堆栈Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/context/properties/EnableConfigurationPropertiesImportSelector$ConfigurationPropertiesBeanRegistrar.class] cannot be opened because it does not exist        at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:646) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:303) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:202) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:170) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:316) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:271) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:91) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:533) ~[spring-context-5.0.13.RELEASE.jar!/:5.0.13.RELEASE]        at org.springframework.cloud.context.named.NamedContextFactory.createContext(NamedContextFactory.java:117) ~[spring-cloud-context-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]        at org.springframework.cloud.context.named.NamedContextFactory.getContext(NamedContextFactory.java:85) ~[spring-cloud-context-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]        at org.springframework.cloud.netflix.ribbon.SpringClientFactory.getContext(SpringClientFactory.java:118) ~[spring-cloud-netflix-ribbon-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]        at org.springframework.cloud.context.named.NamedContextFactory.getInstance(NamedContextFactory.java:126) ~[spring-cloud-context-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]        at org.springframework.cloud.netflix.ribbon.SpringClientFactory.getInstance(SpringClientFactory.java:108) ~[spring-cloud-netflix-ribbon-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]

这个错误很奇怪,只要重新编译发布,就不会再出现。这个很有可能是打包问题,还有类加载问题。

查询github上,社区的人说是类加载问题(https://github.com/spring-cloud/spring-cloud-netflix/issues/3101#issuecomment-463382093),首先对于OpenJDK,曾经有一个Bug(https://bugs.openjdk.java.net/browse/JDK-8172726): 对于ParallelStream,我们知道默认是由JDK启动时默认启动的大小为CPU核数减1的CommonForkJoinPool执行。在多线程多类加载器环境下,这个CommonForkJoinPool可能会有Bug,就是调用Thread.contextClassLoader的时候,返回的是第一个使用CommonForkJoinPool的代码的Classloader,而不是系统根ClassLoader,这样会导致类找不到。

社区修复了这个Bug,只不过是在下一个大版本,也就是GreenWich上,对于Finchley,并没有修复。

我们考虑两种解决方案:

  1. 升级到GreenWich,这个改动很大,从Finchley到GreenWich,Bean初始化机制,JDBC连接池,等等都有了很多变化,短期内耗时费力。

  2. 参考:https://github.com/spring-cloud/spring-cloud-commons/commit/b38ce54410af8fc62d8ae6fe694b580e509ae73a#diff-8c70f107deac71db815f81fa81d5f947,覆盖源码,修改org.springframework.cloud.context.named.NamedContextFactory:

protected AnnotationConfigApplicationContext createContext(String name) {                AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();                if (this.configurations.containsKey(name)) {                        for (Class configuration : this.configurations.get(name)                                        .getConfiguration()) {                                context.register(configuration);                        }                }                for (Map.Entry entry : this.configurations.entrySet()) {                        if (entry.getKey().startsWith("default.")) {                                for (Class configuration : entry.getValue().getConfiguration()) {                                        context.register(configuration);                                }                        }                }                context.register(PropertyPlaceholderAutoConfiguration.class,                                this.defaultConfigType);                context.getEnvironment().getPropertySources().addFirst(new MapPropertySource(                                this.propertySourceName,                                Collections. singletonMap(this.propertyName, name)));                if (this.parent != null) {                        // Uses Environment from parent as well as beans                        context.setParent(this.parent);                        //在这里添加代码,使用parent的类加载器                        context.setClassLoader(this.parent.getClassLoader());                }                context.setDisplayName(generateDisplayName(name));                context.refresh();                return context;        }

这样也是一种应急方案,短期内解决问题。留足时间升级。

到此,相信大家对"OpenJDK11与Spring Cloud Finchley的不兼容问题与解决方法"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

问题 方法 代码 内容 方案 时候 环境 短期 社区 错误 升级 学习 查询 实用 很大 更深 也就是 兴趣 内耗 只不过 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 开洛奇软件开发有限公司 肇庆数字软件开发价目表 宁夏软件开发定制怎么收费 阿里云服务器搭建翻墙 u盘做服务器系统安装系统 联通宽带服务器中间那个灯不亮 mc服务器管理员必备方块 域服务器下对动态ip管理 潮州数据链软件开发优化价格 黑客要有自己的服务器吗 软件开发无形资产固定资产投资 武汉大学网络安全学院的领导班子 软件开发团队与选题 方舟70人服务器1个月多少钱 qq魔法表情怎么找不到服务器 开发软件开发定制 苏州软件开发园区有公司么 青岛崂山区软件开发公司 数据库计算平均年龄的函数 如何用vb打开软件数据库 mpp数据库 产品选型 阿里云服务器搭建翻墙 什么是服务器组网 网络安全渗透培训哪家好 深圳工业软件开发收费报价表 手机怎么解除连接数据库 交通卡充值服务器维护 手机软件开发工程师执业要求 商业地产 互联网科技 将数据库中的表在页面中显示
0