org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource
进行测试的时候提示错误信息
@Test
public void testPageHelper() throws Exception {
//初始化spring容器
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(“classpath:spring/applicationContext-dao.xml”);
//从容器中获得Mapper代理对象
TbItemMapper itemMapper = applicationContext.getBean(TbItemMapper.class);
//执行sql语句之前设置分页信息使用PageHelper的startPage方法。
PageHelper.startPage(1, 10);
//执行查询
TbItemExample example = new TbItemExample();
List list = itemMapper.selectByExample(example);
//取分页信息,PageInfo。1、总记录数2、总页数 。当前页码
PageInfo pageInfo = new PageInfo<>(list);
System.out.println(pageInfo.getTotal());
System.out.println(pageInfo.getPages());
System.out.println(list.size());
}
此异常,为:注入 bean 失败异常。
说白了,出现这个异常,就是找不到对应的 bean 啦!能够导致 bean 注入失败的原因包括以下几种但不限于这几种:
对应的 bean 没有添加注解;
对应的 bean 添加注解错误,例如将 Spring 的@Service错选成 dubbo 的;
选择错误的自动注入方法等。