我有一个配置类
@ConfigurationProperties(prefix = "app.config")
public class AppConfig {
private BrickConfig brickConfig;
}
现在BrickConfig是父类
@Getter
@Setter
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.EXISTING_PROPERTY,
property = "brickConfigType")
@JsonSubTypes({
@JsonSubTypes.Type(value = ValueCopyBrickConfig.class, name = "COPY_VALUE")
})
public class BrickConfig {
private String level;
private BrickConfigType brickConfigType;
}
ValueCopyBrickConfig是子类
@Getter
@Setter
public class ValueCopyBrickConfig extends BrickConfig {
private String copyFrom;
private String copyTo;
public ValueCopyBrickConfig() {
setBrickConfigType(BrickConfigType.COPY_VALUE);
}
}
及以下是我的应用程序的内容。yml
app:
config:
brickConfig:
copyFrom: standardSize
copyTo: displaySize
level: sku
brickConfigType: COPY_VALUE
问题是当应用程序启动时,我得到了BrickConfig的实例而不是ValueCopyBrickConfig。 如何获取ValueCopyBrickConfig实例?