spring3.0 整合 junit 遇到的坑

主要包为以下:

junit-4.12.jar
org.springframework.test-3.0.1.RELEASE-A.jar
spring-context-3.0.1.RELEASE.jar
hamcrest-core-1.3.jar

主要的是包匹配问题,一定要了解自己spring包版本

错误:

1.The type org.springframework.context.ApplicationContextInitializer cannot be resolved. It is indirectly referenced from required .class files

主要为spring-context包未导入导致注解@ContextConfiguration(locations="classpath:XXX.xml")加入后类报错,

解决:导入spring-context-3.0.1.RELEASE.jar包就可以了.

2.java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;

这个的错误是因为导入了一个高版本org.springframework.test导致spring-context里边类和org.springframework.test不匹配导致的。

解决:导入org.springframework.test-3.0.1.RELEASE-A.jar运行自己的测试类完美解决。

猜你喜欢

转载自blog.csdn.net/lhzjj/article/details/82219555
今日推荐