springboot升级: Failed to initialize DiscoveryClient

目标版本

<spring.boot.version>2.5.15</spring.boot.version>

<spring-framework.version>5.3.39</spring-framework.version>

<spring-cloud.version>2020.0.6</spring-cloud.version>                

这应该是在jdk8下 的最大能力了,再升级就要升级到jdk17了

问题

贴一段报错

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient!
   at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:646)
   at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:626)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
   at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:375)
   at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:376)
   at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:179)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:372)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:209)
   at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:127)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:115)
   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:498)
   at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282)
   at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:485)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:762)
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:707)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration$$EnhancerBySpringCGLIB$$c2ad3cf.getEurekaClient(<generated>)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:54)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:38)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:83)
   at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:183)
   at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:58)
   at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:365)
   at java.lang.Iterable.forEach(Iterable.java:75)
   at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:160)
   at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:128)
   at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:949)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:594)
   at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
   at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780)
   at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:453)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:343)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1370)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1359)
   at com.******.SystemAdminApplication.main(SystemAdminApplication.java:24)
   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:498)
   at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
   at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.discovery.EurekaClient]: Factory method 'eurekaClient' threw exception; nested exception is java.lang.RuntimeException: Failed to initialize DiscoveryClient!
   at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
   at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:641)
   ... 49 common frames omitted
 Caused by: java.lang.RuntimeException: Failed to initialize DiscoveryClient!
   at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:436)
   at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:283)
   at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:279)
   at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:66)
   at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:295)
   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:498)
   at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
   ... 50 common frames omitted
 Caused by: java.lang.NoClassDefFoundError: com/sun/jersey/client/apache4/ApacheHttpClient4
   at com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories.newTransportClientFactory(Jersey1TransportClientFactories.java:59)
   at com.netflix.discovery.DiscoveryClient.scheduleServerEndpointTask(DiscoveryClient.java:528)
   at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:423)
   ... 59 common frames omitted
 Caused by: java.lang.ClassNotFoundException: com.sun.jersey.client.apache4.ApacheHttpClient4
   at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
   at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
   ... 62 common frames omitted
 2025-03-18 16:58:09 --- [main] WARN  org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
 2025-03-18 16:58:09 --- [main] INFO  com.alibaba.druid.pool.DruidDataSource - {dataSource-1} closing ...
 2025-03-18 16:58:09 --- [main] INFO  com.alibaba.druid.pool.DruidDataSource - {dataSource-1} closed
 2025-03-18 16:58:09 --- [main] INFO  org.apache.catalina.core.StandardService - Stopping service [Tomcat]
 2025-03-18 16:58:09 --- [main] ERROR org.springframework.boot.SpringApplication - Application run failed
 org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration'; nested exception is java.lang.NullPointerException
   at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:186)
   at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:58)
   at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:365)
   at java.lang.Iterable.forEach(Iterable.java:75)
   at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:160)
   at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:128)
   at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:949)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:594)
   at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
   at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780)
   at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:453)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:343)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1370)
   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1359)
   at com.*****.SystemAdminApplication.main(SystemAdminApplication.java:24)
   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:498)
   at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
   at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
   at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
 Caused by: java.lang.NullPointerException: null
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:54)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:38)
   at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:83)
   at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:183)
   ... 22 common frames omitted
 

追踪

通过标注黄色的报错,我们知道 报错是由于 scopedTarget.eurekaClient' 这个bean无法创建引起的

而这个 scopedTarget.eurekaClient'   是由于  DiscoveryClient  无法初始化导致的

 DiscoveryClient  无法初始化是由于 java.lang.NoClassDefFoundError: com/sun/jersey/client/apache4/ApacheHttpClient4  没有这个类导致的

那么我们只需要解决这个类的问题就好了

这类的maven坐标如下

<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-apache-client4</artifactId>
</dependency>

一般 NoClassDefFoundError  这种报错一般由于以下原因导致

1、没有引入

一般直接引入对应的版本即可

2、引入多个版本导致冲突

通过统一版本解决,如果是间接引入可以在直接引入的包下面排除掉这个依赖

  <dependency>
    <groupId>com.example.group</groupId>
    <artifactId>dependency-A</artifactId>
    <version>1.0.0</version>   
    <exclusions>
      <exclusion>
        <groupId>com.example.group</groupId>
        <artifactId>dependency-C</artifactId>
      </exclusion>
    </exclusions>
  </dependency>

tips: 提供一个命令 帮助 查看依赖树 

mvn dependency:tree

解决

具体到升级spring boot这个问题

Spring Cloud 2020.0.x(Ilford)与 Jersey 的兼容性
在 Spring Cloud 2020.0.x 版本中,Eureka 客户端默认已弃用 Jersey 1.x,并改为使用 Spring 的 WebClient(基于 Reactor Netty)。

所以我们需要手动引入

<dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-apache-client4</artifactId>
    <version>1.19.4</version>
</dependency>

<think>好的,我现在需要解决用户遇到的“Failed to initialize OpenGL”的RuntimeError问题。根据用户提供的引用内容,有几个可能的原因和解决方法需要梳理。 首先,用户提到在引用[1]中,使用mujoco_py的render()函数获取相机图片时,需要移除MjViewer对象和调整环境变量LD_PRELOAD。这可能是因为MjViewer和OpenGL的初始化存在冲突,导致无法正确加载库。因此,解决办法之一是检查代码中是否创建了MjViewer实例,如果有的话,应该去掉它,并确保环境变量中没有设置LD_PRELOAD指向libGLEW.so。此外,可能需要检查其他可能冲突的环境变量设置。 接下来,引用[2]讨论了OpenGL帧缓冲对象的编程实例,涉及初始化窗口和渲染循环。如果用户在初始化OpenGL上下文时失败,可能是窗口创建或GLAD/GLFW初始化的问题。需要确保正确初始化GLFW,设置合适的OpenGL版本,并加载GLAD的函数指针。同时,检查显卡驱动是否支持所需的OpenGL版本,比如4.3以上。 引用[3]提到了Nvidia显卡驱动版本不匹配的问题,解决方案包括重新安装驱动并添加--no-nouveau-check选项。驱动问题确实会导致OpenGL初始化失败,尤其是当驱动版本与内核模块不匹配时。用户需要确认Nvidia驱动是否正确安装,使用nvidia-smi命令检查状态,必要时卸载旧驱动并重新安装最新版本,同时处理nouveau驱动的冲突。 综合以上信息,可能的解决步骤包括:检查代码中是否有多余的MjViewer对象,调整环境变量,验证OpenGL上下文初始化步骤是否正确,更新或重新安装显卡驱动,以及确保系统依赖库如libglew-dev已安装。此外,用户可能需要检查系统日志或错误输出,以获取更具体的错误信息,帮助进一步诊断问题。 最后,生成相关问题时应围绕OpenGL初始化失败的不同原因,如环境变量配置、驱动问题、代码初始化步骤等,帮助用户扩展理解和排查其他潜在问题。</think>要解决“Failed to initialize OpenGL”的RuntimeError错误,可按照以下步骤排查和修复: --- ### **1. 检查代码初始化流程** - **移除冲突的MjViewer对象** 若使用`mujoco_py`的`render()`函数获取图像,需删除`MjViewer`的实例化代码。例如: ```python # 错误示例(需删除此行) viewer = mujoco_py.MjViewer(sim) ``` - **调整环境变量** 在Linux系统中,通过以下命令移除冲突的`LD_PRELOAD`设置: ```bash unset LD_PRELOAD # 临时生效 # 或永久生效:编辑 ~/.bashrc 或 ~/.zshrc,删除相关行 ``` 该变量可能强制加载旧版`libGLEW.so`,导致与OpenGL库冲突[^1]。 --- ### **2. 验证OpenGL上下文初始化** - **检查GLFW/GLAD初始化** 确保在创建窗口时正确设置OpenGL版本和配置文件(如核心模式): ```cpp glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); ``` 加载GLAD时需验证返回值: ```cpp if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { throw std::runtime_error("Failed to initialize GLAD"); } ``` 若初始化失败,可能是驱动不支持该版本[^2]。 --- ### **3. 修复显卡驱动问题** - **解决Nvidia驱动版本冲突** 执行以下命令彻底卸载旧驱动并安装新版: ```bash sudo apt purge nvidia-* sudo ./NVIDIA-Linux-x86_64-xxx.run --no-nouveau-check sudo reboot ``` 安装后运行`nvidia-smi`验证驱动状态[^3]。 - **禁用nouveau驱动** 编辑`/etc/modprobe.d/blacklist.conf`,添加: ```bash blacklist nouveau options nouveau modeset=0 ``` 更新后执行`sudo update-initramfs -u`并重启。 --- ### **4. 安装系统依赖库** - **安装OpenGL相关库** 在Ubuntu/Debian中运行: ```bash sudo apt install libgl1-mesa-dev libglew-dev libglfw3-dev ``` --- ### **5. 验证OpenGL支持** - **检查OpenGL版本** 运行命令查看支持的版本: ```bash glxinfo | grep "OpenGL version" ``` 若版本低于代码要求(如4.3),需升级驱动或调整代码版本。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值