zoukankan      html  css  js  c++  java
  • 当spring 对象@Autowired 注入失败或者创建对象Bean失败、No qualifying bean/Error creating bean 的失败情形分析和解决方案

       错误信息

    今天开发的过程中突然出现如下错误:

    Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.smilx.ipayment.dao.XkioskFileMapper' available: 
               expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1716)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1272)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1226)
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
    	... 63 more
    Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ipaymentCheckController': 
               Unsatisfied dependency expressed through field 'XkioskFileMapper'; 
               nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
               No qualifying bean of type 'com.smilx.ipayment.dao.SmilxXkioskFileMapper' available: expected at least 1 bean which qualifies as autowire candidate. 
            Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643)
    	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130)

     以上错误信息大致意思是:No qualifying bean of type 'com.smilx.ipayment.dao.XkioskFileMapper' available 这个dao层的mapper 依赖注入失败!

       分析及解决办法:

         既然是注入失败首先要检查的就是扫描 Mapper 接口和容器管理配置,Dao层的路径是否配置正确!

            然后检查是否有重名的Bean!

            还有可能在@Service注解的类中直接使用Spring注入的对象,导致加@Service注解的类创建Bean不成功,如下

        @Autowired
        private CommonPropertiesUtil util;
        @Autowired
        private CommonService commonService;
    
        String SECRET_SEX = util.getSecretSex()//直接使用的注入对象util;
        String SECRET_USER = util.getSecretUser();

      把String SECRET_USER = util.getSecretUser()从类中移到方法中运行正常了!

           在这里把自己遇到的问题和解决方案做个记录备份,希望也能解决你的问题

           还有其他情况欢迎评论讨论!

  • 相关阅读:
    OpenSUSE下编译安装OpenFoam
    【一起学OpenFoam】01 OpenFoam的优势
    github+hexo搭建自己的博客网站(七)注意事项(避免read.me,CNAME文件的覆盖,手动改github page的域名)
    github+hexo搭建自己的博客网站(六)进阶配置(搜索引擎收录,优化你的url,添加RSS)
    github+hexo搭建自己的博客网站(五)进阶配置(畅言实现博客的评论)
    github+hexo搭建自己的博客网站(三)主题之外的一些基本配置(图片位置,文章目录功能)
    github+hexo搭建自己的博客网站(二)更换主题yilia
    github+hexo搭建自己的博客网站(一)基础入门
    git入门(4)团队中git保管代码常用操作
    node的包管理工具:yarn和npm
  • 原文地址:https://www.cnblogs.com/aitree/p/14278975.html
Copyright © 2011-2022 走看看