Spring MVC Maven Jar Hell:“ExtendedMappingJacksonJsonView”类型的层次结构不一致

时间:2016-05-04 07:35:58

标签: java spring maven spring-web

我已尽力修复此错误,在我的pom文件中添加了一些排除项,但仍然无法弄清楚为什么会出现此错误。

的pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.demo.project</groupId>
    <artifactId>demoApi</artifactId>
    <version>4.3.0.BUILD-SNAPSHOT</version>
    <name>demoApi</name>
    <description>HTTP REST WebService</description> 
    <properties>
        <spring.version>4.2.5.RELEASE</spring.version>
        <spring.integration.version>4.2.5.RELEASE</spring.integration.version>
        <spring.security.version>4.0.4.RELEASE</spring.security.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-core</artifactId>
            <version>${spring.integration.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-http</artifactId>
            <version>${spring.integration.version}</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <artifactId>org.springframework</artifactId>
                    <groupId>spring-webmvc</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.7</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.security.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
            <scope>compile</scope>
            <exclusions>
                <exclusion>
                    <artifactId>org.springframework</artifactId>
                    <groupId>spring-webmvc</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.springframework</artifactId>
                    <groupId>spring-web</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.springframework</artifactId>
                    <groupId>spring-beans</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.springframework</artifactId>
                    <groupId>spring-core</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>org.springframework</artifactId>
                    <groupId>spring-context</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.3.2</version>
            <scope>compile</scope>
        </dependency> -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>18.0</version>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
    </dependencies> 
    <packaging>war</packaging>
    <build>
        <finalName>demoApi</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我收到此错误的代码

package org.springframework.integration.samples.rest.json.view;

import java.util.Map;

import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

/**
 * ExtendedMappingJacksonJsonView.java: This class extends the Spring's MappingJacksonJsonView
 * <p>
 * Note: The source code for this class is taken from the forum posted by AhungerArtist
 *       at http://forum.springsource.org/archive/index.php/t-84006.html
 * <p>
 * @author Vigil Bose
 * @author Gary Russell
 */
public class ExtendedMappingJacksonJsonView extends MappingJackson2JsonView {

    @SuppressWarnings({"rawtypes" })
    @Override
    protected Object filterModel(Map<String, Object> model){
        Object result = super.filterModel(model);
        if (!(result instanceof Map)){
            return result;
        }

        Map map = (Map) result;
        if (map.size() == 1){
            return map.values().toArray()[0];
        }
        return map;
    }
}

编辑:依赖树输出

[INFO]com.demo.project:demoApi:war:4.3.0.BUILD-SNAPSHOT
[INFO] +- org.springframework:spring-oxm:jar:4.2.5.RELEASE:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] +- org.springframework:spring-test:jar:4.2.5.RELEASE:test
[INFO] +- org.springframework.integration:spring-integration-core:jar:4.2.5.RELE
ASE:compile
[INFO] +- org.springframework.integration:spring-integration-http:jar:4.2.5.RELE
ASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.2.5.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.2.5.RELEASE:compile
[INFO] +- org.hamcrest:hamcrest-all:jar:1.3:test
[INFO] +- org.jasypt:jasypt:jar:1.7:compile
[INFO] +- org.springframework:spring-tx:jar:4.2.5.RELEASE:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.springframework.security:spring-security-config:jar:4.0.4.RELEASE:
compile
[INFO] +- org.springframework.security:spring-security-web:jar:4.0.4.RELEASE:com
pile
[INFO] +- org.mockito:mockito-core:jar:1.9.5:test
[INFO] +- org.springframework:spring-jdbc:jar:4.2.5.RELEASE:compile
[INFO] +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] +- com.oracle:ojdbc6:jar:11.2.0:compile
[INFO] +- com.google.guava:guava:jar:18.0:compile
[INFO] +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] \- javax.inject:javax.inject:jar:1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.143 s
[INFO] Finished at: 2016-05-04T13:44:59+05:30
[INFO] Final Memory: 14M/197M
[INFO] ------------------------------------------------------------------------

编辑2:忘了提一件重要的事情。我们没有使用Maven回购,而是使用我们自己的私人回购。我已下载所有罐子并在我们的仓库中进口。我反复运行mvn clean -U install以查看是否存在任何错误并进行修复。

感谢所有回答的人。由于我不得不尽快完成任务,我决定使用Spring WS而不是JAX-RS!我们已经有了Spring REST WS,所以决定进一步使用它。如果只有我的组织放弃使用私人回购的想法,我就不会遇到这种混乱。

1 个答案:

答案 0 :(得分:2)

有时会发生这些错误,因为无法解析层次结构中的某些接口/类。例如:错误在您的类中 - 类X,X继承Y,反过来,Y继承Z.但是,编译器无法解析z(在上面的错误中),因为z属于未包含的库。因此,您必须将包含z的包添加到类路径/或项目的Java构建路径(如果您使用的是eclipse)。希望它可能会有所帮助。