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后加上*就可以了。
本文介绍了解决Spring JUnit单元测试中出现的FailedtoLoadApplicationContext错误的方法。该错误通常由spring-mybatis.xml中的classpath配置不当引起。通过在@ContextConfiguration注解中的classpath后添加星号(*),可以避免因项目引用中重复的配置文件导致的问题。
1830

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



