NoClassDefFoundError:Spring Cloud Brixton.SR7 和 Spring Cloud Camden.SR3 上的 NameCoder [英] NoClassDefFoundError: NameCoder at Spring Cloud Brixton.SR7 and Spring Cloud Camden.SR3

查看:47
本文介绍了NoClassDefFoundError:Spring Cloud Brixton.SR7 和 Spring Cloud Camden.SR3 上的 NameCoder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于所有 Camden 版本以及现在在 Brixton.SR7 上,启动 Spring Boot 应用程序时会出现以下与 Eureka 客户端相关的问题:

For all the Camden releases and now on the Brixton.SR7 as well, the following issue related to the Eureka Client occurs when starting the Spring Boot app:

java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCoder

例如,我有一个带有 @EnableDiscoveryClient 注释的 Spring Boot 应用程序...

For an instance I have a Spring Boot app having the @EnableDiscoveryClient annotation...

最近我一直在将 Spring Cloud 依赖项改回 Brixton.SR6,以消除此错误.当然,我想使用最新版本的 Spring Cloud,但我该如何正确修复此错误?

Lately I’ve been changing the Spring Cloud dependencies back to Brixton.SR6 in order to get rid of this error. Certainly, I want to use the latest versions of the Spring Cloud but how could I fix this error the right way?

谢谢

控制台输出如下:

2016-11-30 13:09:50.166  INFO 9248 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2016-11-30 13:09:50.177 ERROR 9248 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.context.ApplicationContextException: Failed to start bean 'org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration'; nested exception is 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.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:879) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:545) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar:1.4.2.RELEASE]
    at com.citifintech.ReferenceZipkinServiceApplication.main(ReferenceZipkinServiceApplication.java:15) [classes/:na]
Caused by: 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.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:345) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:359) ~[spring-cloud-context-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:176) ~[spring-cloud-context-1.1.6.RELEASE.jar:1.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:340) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) ~[spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192) ~[spring-aop-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at com.sun.proxy.$Proxy82.getApplications(Unknown Source) ~[na:na]
    at org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration.maybeInitializeClient(EurekaDiscoveryClientConfiguration.java:120) ~[spring-cloud-netflix-eureka-client-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration.start(EurekaDiscoveryClientConfiguration.java:97) ~[spring-cloud-netflix-eureka-client-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    ... 14 common frames omitted
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:189) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    ... 29 common frames omitted
Caused by: java.lang.RuntimeException: Failed to initialize DiscoveryClient!
    at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:441) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:304) ~[eureka-client-1.4.12.jar:1.4.12]
    at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:51) ~[spring-cloud-netflix-eureka-client-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:192) ~[spring-cloud-netflix-eureka-client-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$c1700a5f.CGLIB$eurekaClient$1(<generated>) ~[spring-cloud-netflix-eureka-client-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$c1700a5f$$FastClassBySpringCGLIB$$3759430b.invoke(<generated>) ~[spring-cloud-netflix-eureka-client-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration$$EnhancerBySpringCGLIB$$c1700a5f.eurekaClient(<generated>) ~[spring-cloud-netflix-eureka-client-1.2.3.RELEASE.jar:1.2.3.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
    ... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCoder
    at com.netflix.discovery.converters.wrappers.CodecWrappers$XStreamXml.<init>(CodecWrappers.java:358) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.converters.wrappers.CodecWrappers.create(CodecWrappers.java:133) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.converters.wrappers.CodecWrappers.getEncoder(CodecWrappers.java:75) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.converters.wrappers.CodecWrappers.getEncoder(CodecWrappers.java:66) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.provider.DiscoveryJerseyProvider.<init>(DiscoveryJerseyProvider.java:77) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl$EurekaJerseyClientBuilder$MyDefaultApacheHttpClient4Config.<init>(EurekaJerseyClientImpl.java:194) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl$EurekaJerseyClientBuilder.build(EurekaJerseyClientImpl.java:170) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory$JerseyEurekaHttpClientFactoryBuilder.buildLegacy(JerseyEurekaHttpClientFactory.java:205) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory$JerseyEurekaHttpClientFactoryBuilder.build(JerseyEurekaHttpClientFactory.java:186) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.jersey.JerseyEurekaHttpClientFactory.create(JerseyEurekaHttpClientFactory.java:143) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.shared.transport.jersey.TransportClientFactories.newTransportClientFactory(TransportClientFactories.java:49) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.DiscoveryClient.scheduleServerEndpointTask(DiscoveryClient.java:477) ~[eureka-client-1.4.12.jar:1.4.12]
    at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:428) ~[eureka-client-1.4.12.jar:1.4.12]
    ... 43 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.xstream.io.naming.NameCoder
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_111]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[na:1.8.0_111]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_111]
    ... 56 common frames omitted

这是 pom.xml :`http://maven.apache.org/xsd/maven-4.0.0.xsd">4.0.0

Here is the pom.xml : ` http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.financial</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>client-service</name>
<description>Reference application</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Camden.SR3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

`

这是应用程序的主类:

package com.financial;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

@EnableDiscoveryClient
@SpringBootApplication
public class ClientServiceApplication {

public static void main(String[] args) {
    SpringApplication.run(ClientServiceApplication.class, args);
 }
}

最后是 bootstrap.properties

spring.application.name=client-service
spring.cloud.config.uri=http://localhost:8888

推荐答案

我花了一些时间仔细研究这个问题......所以异常是由于 NameCoder 类在xstream 库.Eureka 实现使用此库.

I had some time to take a closer look into this issue… so the exception is caused by the absence of the NameCoder class in the xstream library. This library is used by Eureka implementation.

那么,到目前为止,xstream 的最新版本是 1.4.9,这是包含在 Camden.SR3Brixton 的托管依赖项中的版本.SR7.

Now then, xstream latest version to this date is 1.4.9 which is the one that is included on the managed dependencies for Camden.SR3 and Brixton.SR7.

包含 NameCoder 类的最新版本是 xstream-1.4.8 所以我不得不修改 pom.xml声明了 eureka 依赖项,因为我的所有项目都有 eureka 服务器或客户端使用依赖项 xstream 版本 1.4.8 而不是 Camden.SR3 托管依赖项提供的依赖项.可以肯定的是,在 maven 中,根据项目的结构,有几种替代方法可以实现这一点,但最直接的方法如下:

The latest version that includes the NameCoder class is the xstream-1.4.8 so I had to modify the pom.xml right where the eureka dependency is stated, for all of my projects have eureka server or client to use the dependency xstream version 1.4.8 instead of the provided by the Camden.SR3 managed dependencies. For sure in maven there are several alternatives to accomplish this depending of the structure of the project, but the most straight forward way is as follows:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
    <exclusions>
        <exclusion>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>                        
        </exclusion>
     </exclusions>
</dependency>       

<dependency>
    <groupId>com.thoughtworks.xstream</groupId>
    <artifactId>xstream</artifactId>
    <version>1.4.8</version><!--$NO-MVN-MAN-VER$-->
</dependency>

现在,需要注意的是,Eureka 当前的实现如何使用 NameCoder 类作为 Spring Cloud xstream 库的版本>Camden.SR3 和 Brixton.SR7 版本是 xstream-1.4.9 哪个没有这个类?由于 maven 最终自动解决了一些多重依赖关系,这个问题可能在测试包期间被忽视了,但是在使用最新版本的 Spring Cloud 实现 Eureka 服务时,有必要进行此更改,至少目前是这样.

Now then, the point to notice is that how the Eureka current implementations use the NameCoder class being that the version of the xstream library provided by the Spring Cloud Camden.SR3 and Brixton.SR7 releases is xstream-1.4.9 which doesn’t have precisely this class? Possibly this issue went under the radar during the testing bundle because of some multiple dependencies that maven ended up solving automatically, however when implementing Eureka service with the latest release of Spring Cloud it will be necessary to do this change, at least for the time being.

这篇关于NoClassDefFoundError:Spring Cloud Brixton.SR7 和 Spring Cloud Camden.SR3 上的 NameCoder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆