Injection of resource dependencies failed; nested exception is org.springframework.beans.factor的报错解决

本文详细解析了Spring框架中Bean创建异常的原因及解决过程,包括因资源依赖注入失败、Mapper XML配置错误等问题,最终通过修正namespace命名空间解决了问题。

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

报错信息

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘adminLoginAction’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘adminServiceImpl’: Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘adminDAOImpl’ defined in file [xxxx\software\target\software\WEB-INF\classes\cn\edu\nchu\student\dao\impl\AdminDAOImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis.cfg.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Mapped Statements collection already contains value for sanxiaoNS.doCreate

解决过程(网上方法总结)

参考文档:https://www.cnblogs.com/enshrineZither/p/3484534.html

  1. beans 的xml里面没有配置
    <context:component-scan base-package=“package-name”/>
  2. 调用死循环
@Repository
public class ADaoImpl extends BaseDaoImpl implements ADao {
 
   @Resource
    private ADao aDao;
 
    @Override
    public int addInbox(TInbox inbox) {
        ....
        ......
        aDao.delete(id);
    }
   @Override
    public int delete(Long id) {
        .....
    }
}

即XyyyyDao实现里面,调用了他接口的本身方法,导致,加载ADaoImpl需要先加载完ADao,而ADao却还没有加载!
3. …

最终解决

一开始在网上搜寻各类方法,发现不存在所说的问题,因为一开始的编译是正常的,增加了一个功能模块后出现了此类问题,最后发现是Mapper.xml中的namespace没有对应:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="sanxiaoNS"> //我的是这里出现了问题,名称不匹配,修改成对应正确即可!

    <resultMap id="articleResultMap" type="Article">
        <id property="title" column="title"/>
        <result property="time" column="time"/>
        <result property="name" column="name"/>
        <result property="image" column="image"/>
        <result property="content" column="content"/>
        <result property="file" column="file"/>
    </resultMap>
    <insert id="doCreate" parameterType="Article">
        INSERT INTO article(title,time,name,image,content,file) VALUES (#{title},#{time},#{name},#{image},#{content}#{file})
    </insert>
    <select id="findAll" parameterType="java.util.List" resultMap="articleResultMap">
        SELECT title,time,name,image,content,file FROM article
    </select>
</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~鱼缸里的猫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值