聪明的骆驼试验弹簧

时间:2015-05-12 08:41:40

标签: spring maven intellij-idea apache-camel

我正在尝试使用带有maven的camel-test-spring和使用intelliJ

我的测试类看起来像这样:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-test-config.xml")
public class MyTest { ... }

使用maven,测试用例被执行并且正常工作。

问题

如果我尝试使用 intelliJ (右键单击testcase / Run" xyz")运行测试用例,则会发生以下错误。

java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;
    at org.springframework.test.context.ContextLoaderUtils.resolveContextLoader(ContextLoaderUtils.java:118)
    at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:594)
    at org.springframework.test.context.ContextLoaderUtils.buildMergedContextConfiguration(ContextLoaderUtils.java:560)
    at org.springframework.test.context.TestContext.<init>(TestContext.java:99)
    at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:121)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:119)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:108)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:41)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

在其他问题中,建议是类路径上有多个版本的spring。 但我现在无法弄清楚哪种依赖是错误的。

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ myproject ---
[INFO] example.project:myproject:war:1.0.0-SNAPSHOT
[INFO] +- example.project:myproject-webservice:jar:1.0.0-SNAPSHOT:compile
[INFO] |  \- org.apache.commons:commons-lang3:jar:3.3.1:compile
[INFO] +- axis:axis:jar:1.4:compile
[INFO] |  +- org.apache.axis:axis-jaxrpc:jar:1.4:compile
[INFO] |  +- org.apache.axis:axis-saaj:jar:1.4:compile
[INFO] |  +- axis:axis-wsdl4j:jar:1.5.1:runtime
[INFO] |  +- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] |  \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] +- org.apache.camel:camel-core:jar:2.14.1:compile
[INFO] |  \- com.sun.xml.bind:jaxb-impl:jar:2.2.7:compile
[INFO] |     +- com.sun.xml.bind:jaxb-core:jar:2.2.7:compile
[INFO] |     |  +- javax.xml.bind:jaxb-api:jar:2.1:provided
[INFO] |     |  |  +- javax.xml.stream:stax-api:jar:1.0-2:provided
[INFO] |     |  |  \- javax.activation:activation:jar:1.1:provided
[INFO] |     |  \- com.sun.istack:istack-commons-runtime:jar:2.16:compile
[INFO] |     \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12:compile
[INFO] |        \- javax.xml.bind:jsr173_api:jar:1.0:compile
[INFO] +- org.apache.camel:camel-ognl:jar:2.14.1:compile
[INFO] |  +- org.apache.servicemix.bundles:org.apache.servicemix.bundles.ognl:jar:3.0.8_1:compile
[INFO] |  \- org.apache.servicemix.bundles:org.apache.servicemix.bundles.javassist:jar:3.12.1.GA_3:compile
[INFO] +- org.apache.camel:camel-cxf:jar:2.14.1:compile
[INFO] |  +- org.apache.cxf:cxf-rt-frontend-jaxrs:jar:3.0.2:compile
[INFO] |  |  +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] |  |  \- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] |  +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:3.0.2:compile
[INFO] |  |  +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] |  |  +- asm:asm:jar:3.3.1:compile
[INFO] |  |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:3.0.2:compile
[INFO] |  |  +- org.apache.cxf:cxf-rt-frontend-simple:jar:3.0.2:compile
[INFO] |  |  \- org.apache.cxf:cxf-rt-ws-addr:jar:3.0.2:compile
[INFO] |  |     \- org.apache.cxf:cxf-rt-ws-policy:jar:3.0.2:compile
[INFO] |  |        \- org.apache.neethi:neethi:jar:3.0.3:compile
[INFO] |  +- org.apache.cxf:cxf-rt-rs-security-oauth:jar:3.0.2:compile
[INFO] |  |  +- org.apache.cxf:cxf-rt-rs-client:jar:3.0.2:compile
[INFO] |  |  \- net.oauth.core:oauth-provider:jar:20100527:compile
[INFO] |  |     \- net.oauth.core:oauth:jar:20100527:compile
[INFO] |  +- org.springframework:spring-core:jar:3.2.11.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:3.2.11.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:3.2.11.RELEASE:compile
[INFO] |  +- org.apache.cxf:cxf-rt-features-clustering:jar:3.0.2:compile
[INFO] |  \- org.apache.cxf:cxf-rt-bindings-soap:jar:3.0.2:compile
[INFO] |     +- org.apache.cxf:cxf-rt-wsdl:jar:3.0.2:compile
[INFO] |     |  \- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] |     \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.0.2:compile
[INFO] +- org.apache.camel:camel-cxf-transport:jar:2.14.1:compile
[INFO] +- org.apache.camel:camel-jaxb:jar:2.14.1:compile
[INFO] +- org.apache.camel:camel-http:jar:2.14.1:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-servlet_3.0_spec:jar:1.0:compile
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.9:compile
[INFO] +- org.apache.camel:camel-spring:jar:2.14.1:compile
[INFO] |  +- org.springframework:spring-aop:jar:3.2.11.RELEASE:compile
[INFO] |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] |  \- org.springframework:spring-tx:jar:3.2.11.RELEASE:compile
[INFO] +- org.apache.camel:camel-spring-javaconfig:jar:2.14.1:compile
[INFO] |  \- org.apache.servicemix.bundles:org.apache.servicemix.bundles.cglib:jar:2.1_3_7:compile
[INFO] +- org.apache.camel:camel-dozer:jar:2.14.1:compile
[INFO] |  \- net.sf.dozer:dozer:jar:5.5.1:compile
[INFO] |     +- commons-beanutils:commons-beanutils:jar:1.9.1:compile
[INFO] |     |  \- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |     \- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] +- org.apache.cxf:cxf-rt-transports-http:jar:3.0.2:compile
[INFO] |  \- org.apache.cxf:cxf-core:jar:3.0.2:compile
[INFO] |     +- org.codehaus.woodstox:woodstox-core-asl:jar:4.4.1:compile
[INFO] |     |  \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] |     \- org.apache.ws.xmlschema:xmlschema-core:jar:2.1.0:compile
[INFO] +- org.apache.camel:camel-jackson:jar:2.14.1:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.4.1:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.4.1:compile
[INFO] |  \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.4.1:compile
[INFO] +- org.springframework:spring-web:jar:3.2.11.RELEASE:compile
[INFO] +- org.hibernate:hibernate-validator:jar:5.1.3.Final:compile
[INFO] |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
[INFO] |  \- com.fasterxml:classmate:jar:1.0.0:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] |  \- log4j:log4j:jar:1.2.17:compile
[INFO] \- org.apache.camel:camel-test-spring:jar:2.14.1:test
[INFO]    +- org.apache.camel:camel-test:jar:2.14.1:test
[INFO]    |  \- junit:junit:jar:4.11:test
[INFO]    |     \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    +- org.springframework:spring-test:jar:3.2.11.RELEASE:test
[INFO]    \- org.springframework:spring-expression:jar:3.2.11.RELEASE:compile

这是我的bom依赖管理块:

<properties>
    <camel-version>2.14.1</camel-version>
    <cxf-version>3.0.2</cxf-version>
    <jaxb-api-version>2.1</jaxb-api-version>
    <spring-version>3.2.11.RELEASE</spring-version>
    <slf4j-version>1.7.5</slf4j-version>
    <junit.version>4.11</junit.version>
    <hamcrest-all.version>1.3</hamcrest-all.version>
    <hibernate-validator.version>5.1.3.Final</hibernate-validator.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cxf</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-cxf-transport</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jaxb</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-ognl</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-javaconfig</artifactId>
            <version>${camel-version}</version>
            <exclusions>
                <!-- I don't want to have spring-test as compile time dependency -->
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-test</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-dozer</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson</artifactId>
            <version>${camel-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-test-spring</artifactId>
            <version>${camel-version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate-validator.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>${jaxb-api-version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf-version}</version>
        </dependency>
        <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>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring-version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${spring-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j-version}</version>
        </dependency>
    </dependencies>
</dependencyManagement>

如果有人能告诉我哪个依赖是错误的话会很棒。

提前致谢,

最高

编辑1:

我已将依赖项更改为camel-test-spring3:

[INFO] \- org.apache.camel:camel-test-spring3:jar:2.14.1:test
[INFO]    +- org.apache.camel:camel-test:jar:2.14.1:test
[INFO]    |  \- junit:junit:jar:4.11:test
[INFO]    |     \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    +- org.springframework:spring-test:jar:3.2.11.RELEASE:test
[INFO]    \- org.springframework:spring-expression:jar:3.2.11.RELEASE:compile

但是在智能方面还有 java.lang.NoSuchMethodError错误。使用maven的Executin仍然有效。

0 个答案:

没有答案
相关问题