嵌套异常是java.lang.NoClassDefFoundError:在pom.xml中进行更改后的MappingJacksonHttpMessageConverter

时间:2016-02-26 10:00:31

标签: java spring spring-mvc spring-boot jackson

我在pom.xml中添加了以下代码段

namespace rd
{
    class Program
    {
        static void Main(string[] args)
        {

            login _login = new login();
            _login.header_message();
            Console.WriteLine(_login.setobj.heading);
            Console.ReadKey();
        }
    }

    public class setget
    {
        public string heading
        { set; get; }
    }

    public class login
    {
        public setget setobj = new setget();
        public void header_message()
        {
            setobj.heading= "*************************************************************************************"+
                "\n*************************************************************************************"+
                "\n*************************                             *******************************"+
                "\n************************* Welcome to Radeon Limited.. *******************************"+
                "\n*************************                             *******************************"+
                "\n*************************************************************************************"+
                "\n*************************************************************************************";
        }
    }
    }

并得到以下异常:

  

嵌套异常是java.lang.NoClassDefFoundError:   组织/ springframework的/ HTTP /变换器/ JSON / MappingJacksonHttpMessageConverter

删除上面的标签后,这个弹簧应用程序运行正常。我想知道为什么?

的pom.xml <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> </parent>
        <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.sas</groupId> <artifactId>sts</artifactId> <name>ApartmentMgmt</name> <packaging>war</packaging> <version>1.0.0-BUILD-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.2.RELEASE</version> </parent> <properties> <java-version>1.6</java-version> <jackson.version>2.6.3</jackson.version> <org.springframework-version>3.1.0.RELEASE</org.springframework-version> <org.aspectj-version>1.6.9</org.aspectj-version> <org.slf4j-version>1.5.10</org.slf4j-version> </properties> <dependencies> <!-- Spring --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>3.2.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>${org.springframework-version}</version><!--$NO-MVN-MAN-VER$--> <exclusions> <!-- Exclude Commons Logging in favor of SLF4j --> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${org.springframework-version}</version><!--$NO-MVN-MAN-VER$--> </dependency>         <!-- AspectJ --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>${org.aspectj-version}</version><!--$NO-MVN-MAN-VER$--> </dependency>
        <!-- Logging --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${org.slf4j-version}</version><!--$NO-MVN-MAN-VER$--> </dependency>         <dependency> <groupId>org.slf4j</groupId> <artifactId>jcl-over-slf4j</artifactId> <version>${org.slf4j-version}</version><!--$NO-MVN-MAN-VER$--> <scope>runtime</scope> </dependency>         <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${org.slf4j-version}</version><!--$NO-MVN-MAN-VER$--> <scope>runtime</scope> </dependency>

<dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version><!--$NO-MVN-MAN-VER$-->
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>

`

2 个答案:

答案 0 :(得分:1)

原因是spring-boot-starter-parent不包含对springframework.web库的依赖。

将此添加到您的pom.xml,以解决您的问题

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.2.5.RELEASE</version>
</dependency>

答案 1 :(得分:1)

您需要在pom.xml添加jackson依赖项。

请参阅以下链接以包含相关的jackson模块

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-dependencies/pom.xml

或者您可以使用弹簧网络模块,以防万一。它将自动带来所有依赖项:

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