报错:Error creating bean with name ‘XXX‘: Unsatisfied dependency expressed through field ‘XXX‘.

报错信息

Error creating bean with name 'residentController': Unsatisfied dependency expressed through field 'signatureUtils'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'signatureUtils' defined in file [D:\Code\p1\ybdjk_new_hlwyy\ybdjk_new_hlwyy\ruoyi-common\target\classes\com\ruoyi\common\gateway\SignatureUtils.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.ruoyi.common.gateway.SignatureUtils]: Constructor threw exception; nested exception is java.lang.UnsupportedOperationException: This is a utility class and cannot be instantiated

使用springboot构建项目时,启动项目出现报错“residentController”的bean时出错:通过字段“signatureUtils”表示不满意的依赖关系;

我在  residentController 这个类引入的时候,用了 @Autowired 

这就需要了解一下 @Autowired 注解的使用前提:

1.获取从spring容器管理的bean,bean中使用的@autowired注解生效,@autowired的属性能从spring容器中注入,是在bean实例化后通过setter方法注入。
2.new出来的对象,不受spring管理,所以使用了@autowired的属性失效为空
3.@confoguration类加载顺序高于被容器管理的类,不能用@autowired,因为还没注入spring容器中,如需要使用spring容器中的bean,在@bean方法的参数定义,会自动注入

总之,我要调用的类里面 signatureUtils 有很多静态方法,直接用signatureUtils.方法名的方式 就可以,不需要 @Autowired ;

根本原因工具类使用@Autowired无法注入bean的原因大多是因为使用了静态方法,相应的,使用@Autowired注入的对象也应该被static修饰,这样spring就无法正常注入bean

所以,我的解决方式是 删掉代码中的 @Autowired,,,,, 然后再其项目时就解决了。


 

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Error creating bean with name 'dictDataController': Unsatisfied dependency expressed through field 'dictDataService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.sxcute.meeting.service.DictDataService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 创建名称为'dictDataController'的Bean时出错:通过字段'dictDataService'表示的依赖关系不满意;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'com.sxcute.meeting.service.DictDataService'的合格Bean可用:预计至少有1个bean符合autowire候选条件。Dependency annotations:{@org.springframework.beans.factory.annotation.Autowired(required=true)} 这个错误表示在创建名为'dictDataController'的Bean时,通过字段'dictDataService'表示的依赖关系无法满足。原因是没有找到符合自动装配条件的类型为'com.sxcute.meeting.service.DictDataService'的合格Bean。可能的原因是忘记在相应的类上加上@Service注解或@Autowired注解,或者没有在启动类上加上@MapperScan注解来扫描Mapper。建议检查相关类的注解配置是否正确并且存在。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [报错-Error creating bean with name xxx: Unsatisfied dependency expressed through field xxx](https://blog.csdn.net/qq_36732146/article/details/123194842)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [问题杂谈(二十七)Error creating bean with name: Unsatisfied dependency expressed through field](https://blog.csdn.net/qq_44648936/article/details/130280387)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值