Java 多态@ConfigurationProperties
考虑这个Java 多态@ConfigurationProperties,java,spring-boot,polymorphism,yaml,deserialization,Java,Spring Boot,Polymorphism,Yaml,Deserialization,考虑这个应用程序。yml: shapes: - type: "square" side: 4 - type: "circle" radius: 6 使用以下Java层次结构: public abstract class Shape { private String type; ... } public class Square extends Shape { private float side; ... } publ
应用程序。yml
:
shapes:
- type: "square"
side: 4
- type: "circle"
radius: 6
使用以下Java层次结构:
public abstract class Shape {
private String type;
...
}
public class Square extends Shape {
private float side;
...
}
public class Circle extends Shape {
private float radius;
...
}
在@ConfigurationProperties
类中使用基类不起作用:
@Configuration
@ConfigurationProperties
public class ShapesProperties {
// BindException
private List<Shape> shapes;
...
}
@配置
@配置属性
公共类形状属性{
//BindException
私有列表形状;
...
}
Spring支持这种场景吗?我已经读过关于转换服务
,活页夹
,转换器
的内容,但我不确定他们是否能解决这个问题。可能的重复