Spring junit做单元测试时,报Failed to load ApplicationContext错误
在做单元测试模块时,提示Failed to load ApplicationContext
,经过查看,发现是测试单元中的一个注解指向了一个不存在的bean,该bean在applicationContext-web.xml中,而我们的代码的注解是
1 |
解决办法就是将这个bean
的定义写在applicationContext-test.xml
中。
当然这种错误也存在其他原因,比如:项目引用了其他模块,并且有相同名称的Spring配置文件,这也会导致Failed to load ApplicationContext
这个错误。
1 |
解决方案
1 |
当然,偷懒也是可以滴,比如:
1 |