在使用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
与本文相关的文章
- springboot项目启动报错Consider defining a bean of type ‘XXX‘ in your configuration.
- Consider defining a bean of type ‘com.XXX‘ in your configuration.
- 安装Python库报错Consider using the `--user` option or check the permissions.
- Consider defining a bean of type ‘**.Mapper‘ in your configuration
- bug---springboot报错Consider the following: If you want an embedded database (H2, HSQL
- Consider defining a bean of type ‘com.luyao.guyue_demo.dao.UserDAO‘ in your configuration.
- consider defining a bean of type没有定义类
- Shiro报错Consider defining a bean named ‘authenticator‘ in your configuration.
- This function or variable may be unsafe. Consider using scanf_s instead.VS中scanf报错的解决方法
- 【Python】使用pip安装第三方库报错 You should consider upgrading via the ‘python -m pip install --upgrade pip‘
- Consider defining a bean of type ‘com.product.client.ProductFeignClient‘ in your configuration.
- Action: Consider defining a bean of type ‘entity.IdWorker‘ in your configuration.
- 报错 :no libwebkitgtk-1.0 detected, some features will be unavailable Consider installing the pack
- pytest allure生成测试报告,报错:Error: pytest: reading from stdin while output is captured! Consider using -s
- Consider defining a bean of type ‘com.ecwid.consul.v1.ConsulRawClient‘ in yo
- VS2019报错:‘fopen‘: This function or variable may be unsafe. Consider using fopen_s instead.
- Consider defining a bean of type ‘xxx‘ in your configuration问题的解决方案
- Consider defining a bean of type 'xxx' in your configuration.
- 解决Mac安装Adobe软件错误代码501问题(PS AI AE PR)mac安装Adobe软件报错501解决方案
- [Cisco Packet Tracer下载教程&安装教程]Cisco Packet Tracer怎么设置成中文?3560-24PS为什么ip helper-address 192.168.8.3报错
评论列表(0)
- 暂无评论