使用spring-boot 1.4.0获取“java.lang.NoSuchMethodError:org.springframework.test.context.MergedContextConfiguration”

时间:2016-05-12 01:09:02

标签: spring-boot

我只使用 Spring-boot 托管工件。由于父pom中定义了所有依赖项,因此模块中的测试失败并出现上述错误。

当我查看依赖树时,我看到包含了两个版本的spring-test,并且两者都被 spring-boot-starter-test:jar:1.4引用。 0.BUILD-快照:编译。请找到dep树输出的部分:

    |  +- org.springframework.boot:spring-boot-starter-test:jar:1.4.0.BUILD-SNAPSHOT:compile
    |  |  +- org.springframework.boot:spring-boot-test:jar:1.4.0.BUILD-SNAPSHOT:compile
    |  |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.0.BUILD-SNAPSHOT:compile
    |  |  +- com.jayway.jsonpath:json-path:jar:2.2.0:compile
    |  |  |  \- net.minidev:json-smart:jar:2.2.1:compile
    |  |  |     \- net.minidev:accessors-smart:jar:1.1:compile
    |  |  |        \- org.ow2.asm:asm:jar:5.0.3:compile
    |  |  +- junit:junit:jar:4.12:compile
    |  |  +- org.assertj:assertj-core:jar:2.4.1:compile
    |  |  +- org.mockito:mockito-core:jar:1.10.19:compile
    |  |  |  \- org.objenesis:objenesis:jar:2.1:runtime
    |  |  +- org.hamcrest:hamcrest-core:jar:1.3:compile
    |  |  +- org.hamcrest:hamcrest-library:jar:1.3:compile
    |  |  +- org.skyscreamer:jsonassert:jar:1.3.0:compile
    |  |  |  \- org.json:json:jar:20140107:compile
    |  |  \- org.springframework:spring-test:jar:4.0.1.RELEASE:compile

    +- org.springframework.boot:spring-boot-starter-test:jar:1.4.0.BUILD-SNAPSHOT:compile
    |  +- org.springframework.boot:spring-boot-test:jar:1.4.0.BUILD-SNAPSHOT:compile
    |  +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.4.0.BUILD-SNAPSHOT:compile
    |  +- com.jayway.jsonpath:json-path:jar:2.2.0:compile
    |  |  \- net.minidev:json-smart:jar:2.2.1:compile
    |  |     \- net.minidev:accessors-smart:jar:1.1:compile
    |  +- junit:junit:jar:4.12:compile
    |  +- org.assertj:assertj-core:jar:2.4.1:compile
    |  +- org.hamcrest:hamcrest-core:jar:1.3:compile
    |  +- org.hamcrest:hamcrest-library:jar:1.3:compile
    |  +- org.skyscreamer:jsonassert:jar:1.3.0:compile
    |  |  \- org.json:json:jar:20140107:compile
    |  \- org.springframework:spring-test:jar:4.2.6.RELEASE:compile

如果需要任何其他详细信息,请与我们联系。 感谢

父POM:删除了所有第三方

    <dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>log4j-over-slf4j</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
            <exclusion>
                <artifactId>javax.transaction-api</artifactId>
                <groupId>javax.transaction</groupId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>xml-apis</artifactId>
                <groupId>xml-apis</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-jdbc</artifactId>
                <groupId>org.apache.tomcat</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-juli</artifactId>
                <groupId>org.apache.tomcat</groupId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-websocket</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-logging-juli</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-el</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-core</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>javax.transaction-api</artifactId>
                <groupId>javax.transaction</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>xml-apis</artifactId>
                <groupId>xml-apis</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-jdbc</artifactId>
                <groupId>org.apache.tomcat</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-juli</artifactId>
                <groupId>org.apache.tomcat</groupId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-websocket</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>javax.transaction-api</artifactId>
                <groupId>javax.transaction</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependency-tools</artifactId>
        <version>1.3.0.BUILD-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>xml-apis</artifactId>
                <groupId>xml-apis</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-jdbc</artifactId>
                <groupId>org.apache.tomcat</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-juli</artifactId>
                <groupId>org.apache.tomcat</groupId>
            </exclusion>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-websocket</artifactId>
            </exclusion>
            <exclusion>
                <artifactId>javax.transaction-api</artifactId>
                <groupId>javax.transaction</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-ws</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>tomcat-embed-core</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-embed-websocket</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-embed-el</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
            <exclusion>
                <artifactId>tomcat-embed-logging-juli</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springmodules</groupId>
        <artifactId>spring-modules-jakarta-commons</artifactId>
        <version>0.8</version>
        <exclusions>
            <exclusion>
                <artifactId>xercesImpl</artifactId>
                <groupId>xerces</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jdom</artifactId>
                <groupId>jdom</groupId>
            </exclusion>
            <exclusion>
                <artifactId>xerces</artifactId>
                <groupId>xerces</groupId>
            </exclusion>
            <exclusion>
                <artifactId>servlet-api</artifactId>
                <groupId>javax.servlet</groupId>
            </exclusion>
            <exclusion>
                <artifactId>xml-apis</artifactId>
                <groupId>xml-apis</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-all</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>1.9.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-core</artifactId>
        <version>1.0-groovy-2.4</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.spockframework</groupId>
        <artifactId>spock-spring</artifactId>
        <version>1.0-groovy-2.4</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-autoconfigure</artifactId>
        <version>LATEST</version>
        <scope>test</scope>
    </dependency>

</dependencies>

参考较旧 spring-test

的模块的POM
    <parent>
        <groupId>com.abc.xyz.dm</groupId>
        <artifactId>decisionmanagement</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../dm-parent/pom.xml</relativePath>
      </parent>
      <artifactId>rms-inspection-model-services</artifactId>
      <url>http://maven.apache.org</url>
      <name>rms-inspection-model-services</name>
      <dependencies>
          <dependency>
              <groupId>com.abc.xyz.dm</groupId>
              <artifactId>dm-common</artifactId>
            <version>${parent.version}</version>
        </dependency>
          <dependency>
              <groupId>com.abc.xyz.dm</groupId>
              <artifactId>dm-generated-classes</artifactId>
            <version>${parent.version}</version>
        </dependency>
      </dependencies>
    </project>

正确 'spring-test'

的模块
    <parent>
            <artifactId>decisionmanagement-parent</artifactId>
            <groupId>com.abc.xyz.dm</groupId>
            <version>1.0-SNAPSHOT</version>
            <relativePath>../dm-parent/pom.xml</relativePath>

        </parent>
        <artifactId>inspection-services</artifactId>
        <name>inspection-services</name>
        <url>http://maven.apache.org</url>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.abc.xyz.dm</groupId>
                <artifactId>dm-common</artifactId>
                <version>${parent.version}</version>
            </dependency>
            <dependency>
                <groupId>com.abc.xyz.dm</groupId>
                <artifactId>dm-generated-classes</artifactId>
                <version>${parent.version}</version>
            </dependency>

        </dependencies>

0 个答案:

没有答案