[英]Spring Jar version with spring-test
我正在為Spring應用程序編寫一些JUnit,使用的Spring版本是
<spring.version>3.2.8.RELEASE</spring.version>
依賴項定義為
<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>
然后在我的JUnit
測試中,我將注釋用作
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:config/test-application-context-datasource.xml")
當我嘗試執行測試用例時,它無法初始化,即它甚至都沒有進入@Before
方法並拋出以下異常:
java.lang.NoClassDefFoundError: org/springframework/core/type/AnnotatedTypeMetadata
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:118)
我相信AnnotatedTypeMetadata僅在4.10.0春季發行之后可用,但是由於我在應用程序中的任何地方都沒有使用它,並且我的spring-test和spring-core的版本相同,所以為什么還要引用它。
有什么想法嗎?
顯然,您的類路徑中具有各種Spring JAR的不兼容版本。
要確定類路徑中存在哪些不兼容的版本(即3.2.8.RELEASE
以外的3.2.8.RELEASE
),請在項目文件夾中執行3.2.8.RELEASE
mvn dependency:tree
。
然后確保避免在類路徑上使用不兼容的版本-例如,通過將排除不必要版本中的任何依賴項的排除項添加到您的Maven POM中,將其作為傳遞性依賴項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.