问题遇到的现象和发生背景
Springboot自定义配置类,jackson序列化后带有额外信息
问题相关代码,请勿粘贴截图
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
自动配置类
@Data
@NoArgsConstructor
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "risk-engine")
public class RiskEngineConfiguration{
public Boolean delay_need;
public Boolean work_need;
public Boolean honest_need;
public Boolean age_need;
public Integer delay_year;
public Integer delay_count;
public Integer delay_return_days;
public Integer delay_money_min;
public Integer age_min;
}
application.yaml
的有关内容
risk-engine:
delay_need: true
work_need: true
honest_need: true
age_need: true
delay_year: 3
delay_count: 2
delay_return_days: 3
delay_money_min: 1000
age_min: 18
controller
@RestController
@RequestMapping("/riskengine")
public class RiskEngineController {
@Autowired
RiskEngineConfiguration riskEngineConfiguration;
@GetMapping("/get")
public RiskEngineConfiguration get(){
System.out.println(riskEngineConfiguration);
return riskEngineConfiguration;
}
}
运行结果及报错内容
get请求:http://localhost:8080/riskengine/get
无限循环:{"parent":null,"name":"platform","registeredAsParallelCapable":true,"unnamedModule":{"name":null,"classLoader":
提示:浅浅的回车了一下,方便查看
{"delay_need":true,"work_need":true,"honest_need":true,"age_need":true,"delay_year":3,"delay_count":2,"delay_return_days":3,"delay_money_min":1000,"age_min":18,
"$$beanFactory":{"parentBeanFactory":null,"beanClassLoader":{"parent":
{"parent":null,"name":"platform","registeredAsParallelCapable":true,"unnamedModule":{"name":null,"classLoader":
{"parent":null,"name":"platform","registeredAsParallelCapable":true,"unnamedModule":{"name":null,"classLoader":
{"parent":null,"name":"platform","registeredAsParallelCapable":true,"unnamedModule":{"name":null,"classLoader":
{"parent":null,"name":"platform","registeredAsParallelCapable":true,"unnamedModule":{"name":null,"classLoader":
我的解答思路和尝试过的方法
- 使用
@Value
一个个写参数应该是能解决(但这太麻烦了,以后碰到很多参数的类似问题还是要解决) - 与Lombok无关,使用 setter&getter 也是一样的结果
- 猜测:这是SpringBoot自动配置的包装类产生的问题,
我想要达到的结果
我只想要toString类似的内容(只有$$beanFactory
之前的那些)