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

报错信息

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>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据您提供的代码和错误信息,您遇到的问题是依赖注入失败,在您的service类中重复注入了自身,导致了循环依赖。循环依赖会导致Spring框架无法正确创建bean,从而抛出BeanCreationException异常。这个问题可以通过调整依赖注入的方式来解决解决这个问题的一种方法是将自身的依赖注入改为接口的依赖注入。在您的代码中,您可以将注入的类型从具体的实现类改为接口类型。例如,将ADaoImple类改为ADao接口。这样,Spring框架将会通过自动装配将适当的实现类注入到您的service中。 另一种解决方法是重新思考您的设计,避免循环依赖的发生。循环依赖通常是设计上的问题,可能意味着您的代码存在冗余或逻辑错误。您可以尝试重构代码,将功能划分到不同的模块或类中,避免循环依赖的出现。 总结来说,您遇到的问题是因为循环依赖导致的依赖注入失败。您可以通过改变注入的方式或重构代码来解决这个问题。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [解决Injection of resource dependencies ... nested exception is org.springframework.beans.factory.](https://blog.csdn.net/SELECT_BIN/article/details/83864158)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory](https://blog.csdn.net/weixin_41716049/article/details/90752421)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

~鱼缸里的猫

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

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

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

打赏作者

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

抵扣说明:

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

余额充值