Spring和mybatis的整合,JUnit测试错误

pengdott 2017-10-20 09:53:00
spring和mybatis整合完成后,编写测试类,发生如下错误:是哪个配置写得不正确,请帮忙看看
[org.springframework.test.context.TestContextManager] - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@3f56875e] to prepare test instance [org.zsl.testmybatis.TestMyBatis@2b4bac49]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:319)


测试类代码:

@RunWith(SpringJUnit4ClassRunner.class) //表示继承了SpringJUnit4ClassRunner类
@ContextConfiguration(locations = {"classpath:spring-mybatis.xml"})

public class TestMyBatis {
private static Logger logger = Logger.getLogger(TestMyBatis.class);

private IUserService userService = null;

@Test
public void test1() {
User user = userService.getUserById(1);
logger.info(JSON.toJSONString(user));
}
}
...全文
386 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xian_s 2018-09-14
  • 打赏
  • 举报
回复
这是顶层的错误输出,下面应该还有更具体的错误输出
verejava 2018-09-14
  • 打赏
  • 举报
回复
xigua1102 2018-09-13
  • 打赏
  • 举报
回复
如果是web程序的话,先走正常流程,通过页面触发试试看
猫鲨 2018-09-13
  • 打赏
  • 举报
回复
还有错误原因都没贴,有一句"caused by: ..."

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧