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后加上*就可以了。
本文解答了使用SpringJUnit进行单元测试时遇到的Failed to load ApplicationContext错误问题,通过修改@Configuration注解中的classpath路径前缀,避免了项目内相同名称的配置文件冲突,确保测试环境正确加载。
9367

被折叠的 条评论
为什么被折叠?



