Caused by: java.lang.RuntimeException: Failed to initialize DiscoveryClient!

今天在公司为springCloud框架下的项目上线前做打包准备,在准备的过程中发现一个比较有意思的现象特地记下来,为“基友”们提供一下参考,也为使自己在后续碰到同样的问题时能够快速解决。

现象:开发工具内(idea)运行正常的微服务因为改了东西后莫名无法正常启动,报错信息如下

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.instantiateUsingFactoryMethod(ConstructorResolver.java:583)
        ... 47 common frames omitted
Caused by: java.lang.RuntimeException: Failed to initialize DiscoveryClient!
        at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:411)
        at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:269)
        at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:63)
        at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:290)
        at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$7f5dfdbe.CGLIB$eurekaClient$0(<generated>)
        at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$7f5dfdbe$$FastClassBySpringCGLIB$$4fdb82e1.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365)
        at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$7f5dfdbe.eurekaClient(<generated>)
        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)
        ... 48 common frames omitted
Caused by: java.lang.RuntimeException: Cannot create Jersey client
        at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl$EurekaJerseyClientBuilder.build(EurekaJerseyClientImpl.java:182)
        at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory$JerseyEurekaHttpClientFactoryBuilder.buildLegacy(JerseyEurekaHttpClientFactory.java:230)
        at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory$JerseyEurekaHttpClientFactoryBuilder.build(JerseyEurekaHttpClientFactory.java:204)
        at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory.create(JerseyEurekaHttpClientFactory.java:161)
        at com.netflix.discovery.shared.transport.jersey.Jersey1TransportClientFactories.newTransportClientFactory(Jersey1TransportClientFactories.java:59)
        at com.netflix.discovery.DiscoveryClient.scheduleServerEndpointTask(DiscoveryClient.java:485)
        at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:398)
        ... 61 common frames omitted
Caused by: java.lang.RuntimeException: Cannot create Jersey client
        at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.<init>(EurekaJerseyClientImpl.java:61)
        at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl$EurekaJerseyClientBuilder.build(EurekaJerseyClientImpl.java:180)
        ... 67 common frames omitted
Caused by: java.lang.ExceptionInInitializerError: null
        at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:182)
        at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:175)
        at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
        at com.sun.jersey.api.client.Client.init(Client.java:343)
        at com.sun.jersey.api.client.Client.access$000(Client.java:119)
        at com.sun.jersey.api.client.Client$1.f(Client.java:192)
        at com.sun.jersey.api.client.Client$1.f(Client.java:188)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
        at com.sun.jersey.api.client.Client.<init>(Client.java:188)
        at com.sun.jersey.client.apache4.ApacheHttpClient4.<init>(ApacheHttpClient4.java:151)
        at com.sun.jersey.client.apache4.ApacheHttpClient4.<init>(ApacheHttpClient4.java:137)
        at com.sun.jersey.client.apache4.ApacheHttpClient4.create(ApacheHttpClient4.java:181)
        at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.<init>(EurekaJerseyClientImpl.java:53)
        ... 68 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: org.jboss.resteasy.spi.ResteasyProviderFactory
        at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:152)
        at javax.ws.rs.ext.RuntimeDelegate.getInstance(RuntimeDelegate.java:120)
        at javax.ws.rs.core.MediaType.valueOf(MediaType.java:179)
        at com.sun.jersey.core.header.MediaTypes.<clinit>(MediaTypes.java:65)
        ... 81 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.jboss.resteasy.spi.ResteasyProviderFactory
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at javax.ws.rs.ext.FactoryFinder.newInstance(FactoryFinder.java:114)
        at javax.ws.rs.ext.FactoryFinder.find(FactoryFinder.java:207)
        at javax.ws.rs.ext.RuntimeDelegate.findDelegate(RuntimeDelegate.java:135)
        ... 84 common frames omitted

 凭借多年工作经验一眼就判定为包依赖有问题,于是果断把刚刚注掉的自认为没用的依赖包都给放回来,但是仍然不行于是和另一个项目进行了对比,然后没有发现任何可疑的地方,无耐之下只好找到历史版本给回退了一下,OK,一切正常。于是就顺手把一个看着不符合自己习惯的地方给改了一下(处女座,你懂得),结果再次启动同样的异常再次重现,果断重复试验了好几次(屡试不爽)竟然全部复现^_^!,具体改动地方如下:

 

各位“基友”看出区别了吗?就因为两个jar包依赖的顺序不一样,结果却完全不同。

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
根据提供的引用内容,你遇到了一个运行时异常Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: Cannot find implementation。这个异常通常是由于找不到某个类的实现导致的。解决这个问题的方法有以下几种: 1. 检查依赖项:首先,确保你的项目中包含了所需的依赖项。在Android开发中,你可以在项目的build.gradle文件中添加所需的依赖项。例如,如果你使用的是Gradle构建工具,你可以在dependencies部分添加所需的库。然后,重新构建你的项目并运行它。 2. 检查类路径:如果你确定依赖项已经正确添加到项目中,那么可能是类路径的问题。类路径是指Java虚拟机(JVM)用来查找类文件的路径。确保你的类路径包含了所需的类文件。你可以通过在命令行中使用java命令的-cp选项来指定类路径。例如,如果你的类文件位于一个名为lib的文件夹中,你可以使用以下命令来运行你的应用程序: ```shell java -cp lib/ YourMainClass ``` 3. 检查类名和包名:如果你确定依赖项和类路径都没有问题,那么可能是类名或包名的问题。确保你在代码中正确引用了类名和包名。检查你的import语句和类的全限定名是否正确。 4. 清除缓存和重新构建:有时候,清除构建缓存并重新构建项目可以解决一些奇怪的问题。你可以尝试清除你的项目的构建缓存,并重新构建它。 5. 检查编译版本:如果你在使用某个库或框架时遇到了这个问题,确保你的编译版本与该库或框架的要求相匹配。有时候,不同的库或框架需要特定的编译版本才能正常工作。 这些是解决Caused by: java.lang.ClassNotFoundException: Cannot find implementation异常的一些常见方法。根据你的具体情况,你可以尝试其中的一种或多种方法来解决问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值