springboot使用@ConfigurationProperties报错Could not autowire. No beans of ‘String‘ type found.并且程序运行错误

报错

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.atguigu.boot.buhui.Car required a bean of type 'java.lang.String' that could not be found.

解决方案

这是因为自动注入需要无参构造,而我生成构造函数的时候生成的是有参构造。因此只需要进行无参构造进行了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误提示是因为在Spring工程中,找不到类型为 'String' 的 bean。这个错误提示并不会影响程序的编译和运行。解决这个问题的方法有以下几种: 1. 在配置文件中定义一个类型为 'String' 的 bean。根据错误提示,你可以在你的配置文件中添加一个如下的定义:`<bean id="myString" class="java.lang.String"/>` 这样就定义了一个名为 'myString' 的 String 类型的 bean。 2. 将注解 `@Autowired` 改为 `@Resource`。这两个注解的区别在于,`@Autowired` 是Spring的注解,而 `@Resource` 是J2EE的注解。使用 `@Resource` 可以减少Spring的耦合度。同时 `@Autowired` 是按照类型自动注入的,而 `@Resource` 默认按照名称自动注入。所以你可以将 `@Autowired` 注解改为 `@Resource` 注解来解决这个问题。 3. 如果使用 `@Resource` 注解仍然无法解决问题,可以尝试使用 `@Qualifier` 注解来指定具体的 bean。例如:`@Resource @Qualifier("myString")`。 总结一下,解决这个问题的方法有:定义一个类型为 'String' 的 bean、将注解 `@Autowired` 改为 `@Resource` 注解、使用 `@Qualifier` 注解来指定具体的 bean。希望这些方法能够帮助你解决问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Could not autowire. No beans of String type found. Checks autowiring problems in a bean class](https://blog.csdn.net/weixin_41442734/article/details/106771454)[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^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [如何解决Could not autowire. No beans of ‘xxx‘ type found.的问题。](https://blog.csdn.net/weixin_57109001/article/details/118634927)[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^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [解决Could not autowire.No beans of ‘ ‘ type found](https://blog.csdn.net/luoluo95/article/details/125263985)[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^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值