简体   繁体   English

带有春季测试的Spring Jar版本

[英]Spring Jar version with spring-test

I am writing some JUnits for a Spring application, the Spring version used for which is 我正在为Spring应用程序编写一些JUnit,使用的Spring版本是

    <spring.version>3.2.8.RELEASE</spring.version>

the dependencies are defined as 依赖项定义为

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

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

then in my JUnit test i am using the annotations as 然后在我的JUnit测试中,我将注释用作

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:config/test-application-context-datasource.xml")

When i am trying to execute the test case it fails to initialize, ie it doesn't even goes into the @Before method and throws below exception: 当我尝试执行测试用例时,它无法初始化,即它甚至都没有进入@Before方法并抛出以下异常:

java.lang.NoClassDefFoundError: org/springframework/core/type/AnnotatedTypeMetadata
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:118)

AnnotatedTypeMetadata is only available after spring release 4.10.0 i believe, but since i am not using that anywhere in my application and the version of my spring-test and spring-core is same, why is this even getting referred. 我相信AnnotatedTypeMetadata仅在4.10.0春季发行之后可用,但是由于我在应用程序中的任何地方都没有使用它,并且我的spring-test和spring-core的版本相同,所以为什么还要引用它。

Any thoughts? 有什么想法吗?

You obviously have incompatible versions of various Spring JARs on your classpath. 显然,您的类路径中具有各种Spring JAR的不兼容版本。

To figure out which incompatible versions (ie, other than 3.2.8.RELEASE ) are present in your classpath, execute mvn dependency:tree in your project's folder. 要确定类路径中存在哪些不兼容的版本(即3.2.8.RELEASE以外的3.2.8.RELEASE ),请在项目文件夹中执行3.2.8.RELEASE mvn dependency:tree

Then ensure that you avoid having the incompatible versions on your classpath -- for example, by adding exclusions to your Maven POM for any dependencies that are pulling in the unwanted versions as transitive dependencies. 然后确保避免在类路径上使用不兼容的版本-例如,通过将排除不必要版本中的任何依赖项的排除项添加到您的Maven POM中,将其作为传递性依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM