2014-12-05 77 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中添加排除项,以获取将不需要的版本作为传递依赖关系拉入的任何依赖项。