本文介绍了java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCode 在 spring 4.3.1 中设置restful webservice 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 spring 中创建 rest 控制器,但出现此错误:

I want to create rest controller in spring but I get this error :

org.springframework.beans.factory.BeanCreationException:错误用名字创建bean'org.springframework.web.servlet.view.ContentNegotiatingViewResolver#0'在 ServletContext 资源中定义[/WEB-INF/mvc-dispatcher-servlet.xml]:bean初始化失败;嵌套异常是 java.lang.NoClassDefFoundError:com/thoughtworks/xstream/io/naming/NameCoder

这些 jar 文件已正确添加到我的项目中:杰克逊注释:2.1.1/杰克逊核心:2.1.1/杰克逊数据绑定:2.1.2

These jar files were added to my project correctly :jackson-annotations:2.1.1/jackson-core:2.1.1/jackson-databind:2.1.2

<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
              <version>${spring.version}</version>
          </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.2.0.Final</version>
        </dependency>


        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.3.1</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.version}</version>
        </dependency>


        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.1.2</version>
        </dependency>




    </dependencies>

推荐答案

尝试将其添加到您的 pom:

Try adding this to your pom:

<dependency>
    <groupId>com.thoughtworks.xstream</groupId>
    <artifactId>xstream</artifactId>
    <version>1.4.9</version>
</dependency>

这篇关于java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/naming/NameCode 在 spring 4.3.1 中设置restful webservice 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 21:50