org.springframework.beans.factory.BeanCreationException

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 的;
选择错误的自动注入方法等。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值