获取java.lang.ClassNotFoundException:com.thoughtworks.xstream.io.naming.NameCoder

时间:2017-03-02 08:15:26

标签: spring spring-boot netflix-eureka spring-cloud-netflix

尝试使用SpringBoot创建示例Ereka Server应用程序。当启动服务器获取以下异常时。

异常堆栈跟踪

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverCodecs' defined in org.springframework.cloud.netflix.eureka.server.EurekaServerConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.eureka.resources.ServerCodecs]: Factory method 'serverCodecs' threw exception; nested exception is java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCoder
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)

    Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.netflix.eureka.resources.ServerCodecs]: Factory method 'serverCodecs' threw exception; nested exception is java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCoder
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)


    Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCoder
        at com.netflix.discovery.converters.wrappers.CodecWrappers$XStreamXml.<init>(CodecWrappers.java:358)
        at com.netflix.discovery.converters.wrappers.CodecWrappers.create(CodecWrappers.java:133)

POM文件

<project ...>
...
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </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.SR5</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>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
</project>

我已经在POM依赖关系层次结构中验证了xstream:1.4.9依赖关系是否存在于引用java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCode error in setting up restful webservice in spring 4.3.1

enter image description here

请建议我

1 个答案:

答案 0 :(得分:1)

请您查看此链接中建议的答案。它可能会对你有所帮助。

NoClassDefFoundError: NameCoder at Spring Cloud Brixton.SR7 and Spring Cloud Camden.SR3