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

加载应用内容出错,一般由于spring-mybatis.xml中的classpath配置的不对。

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后加上*就可以了。

Logo

脑启社区是一个专注类脑智能领域的开发者社区。欢迎加入社区,共建类脑智能生态。社区为开发者提供了丰富的开源类脑工具软件、类脑算法模型及数据集、类脑知识库、类脑技术培训课程以及类脑应用案例等资源。

更多推荐