spring junit 做单元测试,报 Failed to load ApplicationContext 错误

spring junit 做单元测试,报 Failed to load ApplicationContext 错误。

 

查找了好一会,最后发现。@ContextConfiguration(locations = { "classpath:/spring/applicationContext.xml",
"classpath:/spring/app-config.xml", ……

改成

@ContextConfiguration(locations = { "classpath*:/spring/applicationContext.xml",
"classpath*:/spring/app-config.xml",

就好了。

 

可能是因为项目里引用了其他项目,有相同名称的spring配置文件导致的。在classpath后加上*就可以了。

 

 

如果以上未解决

可以尝试:Clean Project -> mvn install

posted @ 2016-01-17 10:33  牧之丨  阅读(30218)  评论(0编辑  收藏  举报