在使用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
与本文相关的文章
- VS2017报错:error C4996: ‘scanf‘: This function or variable may be unsafe. Consider using scanf_s inste
- 【SpringBoot】Consider defining a bean of type ‘java.lang.String
- 报错-C4996 ‘fopen‘: This function or variable may be unsafe. Consider using fopen_s instead. 解决办法
- Action: Consider defining a bean of type ‘entity.IdWorker‘ in your configuration.
- Consider defining a bean of type ‘com.ecwid.consul.v1.ConsulRawClient‘ in yo
- Action:Consider defining a bean of type ‘AdminPunishService‘ in your configuration. 解决办法
- Consider defining a bean of type 'xxx' in your configuration.
- OpenGL C++编译报错 Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS
- U盘装linux总是不行,U盘安装Linux安装报错及解决方案
- Windows环境golang程序开发 报错exec: gcc: executable file not found in %PATH%
- Windows7x86的DevC++执行不了exe文件,报错Error 216:该版本的%1与您运行的windows版本不兼容。
- Windows系统更新完后进不去Microsoft Store,报错:需要使用新应用以打开此ms-windows-store链接
- Field [price] of type [text] is not supported for aggregation [avg]
- typec扩展坞hdmi没反应_Type C拓展坞没你想的那么简单
- 笔记本电脑有蓝牙连接功能吗_type-c扩展坞问题汇总及解析(发热、Wi-Fi蓝牙锻炼、烧主板)...
- 惠普服务器自动装驱动安装,Win10系统不断自动安装HP打印机驱动且报错0x80240017的解决方法...
- Windows 7系统开机报错ERROR 0199
- 第7章 IoC容器 V (Configuration) -- Spring4.3.8参考文档中文版
- winutils.exe文件下载地址不要钱的以及java中使用mapreuduce报错NativeIO$Windows.access0(LjavalangString;I)Z
- 【LoadRunner报错】 -LR无法直接打开Chrome浏览器
评论列表(0)
- 暂无评论