2014-12-05 125 views
0

我寫一些JUnits的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") 

當我試圖執行測試ca SE它初始化失敗,也就是說,它甚至沒有進入@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的版本是相同的,爲什麼這甚至會被引用。

有什麼想法?

回答

1

你的類路徑中顯然有各種Spring JAR的不兼容版本。

要確定類路徑中存在哪些不兼容的版本(即3.2.8.RELEASE以外),請在項目文件夾中執行mvn dependency:tree

然後確保避免在類路徑中包含不兼容的版本 - 例如,向您的Maven POM中添加排除項,以獲取將不需要的版本作爲傳遞依賴關係拉入的任何依賴項。