java.lang.NoClassDefFoundError:com/thoughtworks/xstream/io/naming/NameCode在Spring 4.3.1中设置restful webservice时出错

far*_*raa 1 spring spring-mvc maven

我想在春天创建休息控制器但我得到这个错误:

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

这些jar文件正确地添加到我的项目中: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>
Run Code Online (Sandbox Code Playgroud)

Gan*_*alf 9

尝试将此添加到您的pom:

<dependency>
    <groupId>com.thoughtworks.xstream</groupId>
    <artifactId>xstream</artifactId>
    <version>1.4.9</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)