在使用SpringBoot为实体类赋值时,使用的是@Value注解,同时在实体类上使用了@data和@AllArgsConstructor注解
发现报错“Consider defining a bean of type ‘java.lang.String‘ in your configuration.”
原因是@Value注解需要使用无参构造;而当我们不为一个类声明任何构造函数时,Java会默认为我们提供一个无参构造,而当我们显示地声明构造函数时,Java就不会为我们提供构造函数。而我却显示地声明了@AllArgsConstructor
在这里,我们使用了lombok的@Data注解,此注解不会为我们提供无参构造,实际上
@Data=@Setter+@Getter+@EqualsAndHashCode.
综上,解决问题的方法已经显而易见了:
我们只要在对应的类上加上一个无参构造的注解即@NoArgsConstructor即可解决问题
使用 @Value 注入配置的时候报错 Consider defining a bean of type ‘java.lang.String‘ in your configuration
与本文相关的文章
- Consider defining a bean of type ‘com.product.client.ProductFeignClient‘ in your configuration.
- SpringBoot: Consider defining a bean of type ‘com.xxx.xxx.xxx.Dao‘ in your configuration.的解决方案
- Consider defining a bean of type ‘com.ecwid.consul.v1.ConsulRawClient‘ in yo
- OpenGL C++编译报错 Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS
- mac电脑安装软件报错:无法检查更新,请检查你的互联网连接
- [Cisco Packet Tracer下载教程&安装教程]Cisco Packet Tracer怎么设置成中文?3560-24PS为什么ip helper-address 192.168.8.3报错
- 联想服务器安装系统蓝屏怎么办,安装Windows操作系统时,蓝屏报错
- Windows环境golang程序开发 报错exec: gcc: executable file not found in %PATH%
- 关于Windows系统下安装Zookeeper以及Zookeeper启动报错问题
- Windows报错:系统管理员设置了系统策略禁止进行此安装。解决方法!
- xp系统打印机服务器报错,XP系统打印机显示Spoolsv.exe应用程序错误如何办?
- Field [price] of type [text] is not supported for aggregation [avg]
- SpringBoot整合Kafka报错: Topic(s) [xxxx] isare not present and missingTopicsFatal is true
- invalid type switch guard:key :=k(type)(non-interface type dns.RR on left)解决方案(转)
- typec扩展坞hdmi没反应_Type C拓展坞没你想的那么简单
- 华为游戏小程序快应用账号登录6004报错集合
- winutils.exe文件下载地址不要钱的以及java中使用mapreuduce报错NativeIO$Windows.access0(LjavalangString;I)Z
- 【避坑指南】Win7虚拟机中VMwareTools 安装报错问题解决
- selenium+python-------- 打开chrome浏览器后闪退没有报错
- Windows10 wireless AC9560 报错无法启动(代码10)该怎么办?
评论列表(0)
- 暂无评论