我有一个类似于下面的配置
spring:
source:
prop1: ['abc', 'def']
prop2: some-value
destination:
prop1: some-other-value
我正在尝试使用以下类阅读上述配置
@Configuration
@ConfigurationProperties(prefix = "spring")
@Getter
@Setter
public class ClientConfiguration {
private Source source;
private Destination destination;
}
@Getter
@Setter
@AllArgsConstructor
@Configuration
@ConfigurationProperties(prefix = "source")
public class Source {
private List<String> prop1;
private String prop2;
}
@AllArgsConstructor
@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "destination")
public class Destination {
private String prop1;
}
但是,我在此设置中遇到错误。
Could not bind properties to ClientConfiguration (prefix=spring, ignoreInvalidFields=false, ignoreUnknownFields=true, ignoreNestedProperties=false); nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'source' of bean class [ClientConfiguration$$EnhancerBySpringCGLIB$$f1eacf3e]: Could not instantiate property type [Source] to auto-grow nested property path; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [Source]: Is it an abstract class?; nested exception is java.lang.InstantiationException: Source
请让我知道如何使用嵌套对象解析嵌套配置。