2016-12-01 119 views
-1

對於所有Camden版本以及現在在Brixton.SR7中,以下與Eureka客戶端相關的問題在啓動Spring Boot應用程序時發生:NoClassDefFoundError:NameCoder在Spring Cloud Brixton.SR7和Spring雲中Camden.SR3

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

對於一個實例我有具有@EnableDiscoveryClient註釋的春天啓動的應用程序...

最近我一直在改變,以便在春季雲依賴性回Brixton.SR6擺脫這種錯誤。當然,我想使用Spring Cloud的最新版本,但我怎麼才能以正確的方式解決這個錯誤?

感謝

控制檯輸出如下:

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

<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 
+0

我們以前從未見過。小心分享重現問題的項目? – spencergibb

+0

嗨,Spence剛剛添加了'pom.xml','bootstrap.properties'和項目的主類。 – Emmanuel780

回答

0

我有一些時間來仔細研究這個問題......所以異常是由缺少的原因引起的NameCoder類在xstream庫中。這個庫被Eureka實現使用。

然後,xstream到此日期的最新版本是1.4.9,這是Camden.SR3Brixton.SR7的託管依賴關係中包含的最新版本。

包含NameCoder類是xstream-1.4.8,所以我不得不改變在尤里卡依賴性規定的pom.xml正確的,我所有的項目都尤里卡服務器或客戶端使用的依賴xstream版本1.4.8,而不是最新版本由Camden.SR3提供的管理依賴關係。爲了確保在Maven中有幾種選擇來完成這個取決於項目的結構,但最直接的方式如下:

<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> 

現在的話,要注意的一點是,如何尤里卡當前實現使用NameCoder類是因爲Spring Cloud Camden.SR3Brixton.SR7版本提供的xstream庫的版本是xstream-1.4.9,它不具有這個類嗎?可能這個問題在測試包期間受到了雷達的影響,因爲maven最終會自動解決多個依賴項,但是,在最新發布的Spring雲中實施Eureka服務時,有必要進行此更改,至少暫時。

1

我有同樣的問題。這與xstream的舊版本(xstream:xstream:jar:1.1.3:compile)有關。 xstream庫更改groupId和Spring雲使用新版本(com.thoughtworks.xstream:xstream:jar:1.4.9:compile)。

使用mvn dependency:tree命令檢查您的類路徑中是否有兩個庫。然後,您可以使用Maven排除從類路徑中刪除舊的。

<dependency> 
    <groupId>GROUPID</groupId> 
    <artifactId>ARTIFACTID</artifactId> 
    <version>X.Y.Z</version> 
    <exclusions> 
     <exclusion> 
      <groupId>xstream</groupId> 
      <artifactId>xstream</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 
相關問題