解决org.springframework.beans.factory.BeanCreationException: Error creating bean with name

本文介绍了Spring Bean创建失败时的排查步骤,包括检查Spring注解扫描配置、类注解使用情况及web.xml中Spring配置文件的加载等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出现这种错误意识就是spring bean创建失败,有好几方面的原因,一步一步查找。


1 . 首先看Spring的注解扫描有没有写

 <context:component-scan base-package="cn.sxt"></context:component-scan>

然后看各个层的类@表示有没有写,成员变量或者set方法上面的@Autowired有没有写 如:

@Repository("userDao")
public class UserDaoImpl extends SqlSessionDaoSupport implements  UserDao{
    @Autowired
    @Override
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        super.setSqlSessionFactory(sqlSessionFactory);
    }
    public List<User> list() {

        return getSqlSession().selectList("cn.sxt.vo.user.mapper.list");
    }

}

2 .以上没有问题就可能是web.xml中spring配置文件没有被加载进去 ,很有可能是listener中的class引用错了,这里是ContexteLoaderListener
不是ContextLoader

<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值