Java ConfigurationProperties和ConstructorBinding的复杂类型DefaultValue

Java ConfigurationProperties和ConstructorBinding的复杂类型DefaultValue,java,spring,spring-boot,Java,Spring,Spring Boot,我希望在默认情况下有一个包含所有字段的不可变属性类。将属性包含到库中。 默认情况下,我可以用简单类型创建一个不可变的属性类,但不能用复杂类型创建。有没有办法将complexe类型的默认值设置到immutable ConfigurationProperties类中 导入lombok.Getter; 导入org.springframework.boot.context.properties.ConfigurationProperties; 导入org.springframework.boot.con

我希望在默认情况下有一个包含所有字段的不可变属性类。将属性包含到库中。 默认情况下,我可以用简单类型创建一个不可变的属性类,但不能用复杂类型创建。有没有办法将complexe类型的默认值设置到immutable ConfigurationProperties类中

导入lombok.Getter;
导入org.springframework.boot.context.properties.ConfigurationProperties;
导入org.springframework.boot.context.properties.ConstructorBinding;
导入org.springframework.boot.context.properties.bind.DefaultValue;
@配置属性(前缀=“foo”)
@构造绑定
@吸气剂
公共最终类属性{
私人最终字符串
私人最终子项目子项目;
公共财产(
@DefaultValue(“foo”)字符串,
anysubperties sub//这里有注释吗?比如@DefaultValue
) {
这个,某物,某物;
this.sub=sub;//始终为空!
}
@吸气剂
公共静态最终类AnySubProperties{
私有字符串最终值;
公共任意子属性(@DefaultValue(“bar”)字符串finalValue){
this.finalValue=finalValue;
}
}
}
在示例中,如果未定义属性(使用
yaml
属性文件
),则
sub
null

我想要设置了
最终值
(带条形码>值)的
sub

谢谢你的回答

使用不带注释的解决方案进行编辑

我找到了一个没有注释的解决方案,但我是一个懒惰的孩子,这就是为什么不可能有一个带有spring注释的解决方案

导入lombok.Getter;
导入org.springframework.boot.context.properties.ConfigurationProperties;
导入org.springframework.boot.context.properties.ConstructorBinding;
导入org.springframework.boot.context.properties.bind.DefaultValue;
@配置属性(前缀=“foo”)
@构造绑定
@吸气剂
公共最终类属性{
私人最终字符串
私人最终子项目子项目;
@构造绑定
公共财产(
@DefaultValue(“foo”)字符串,
anysubperties sub//这里有注释吗?比如@DefaultValue
) {
这个,某物,某物;
this.sub=null!=sub?sub:new anysubperties();
}
@吸气剂
公共静态最终类AnySubProperties{
私有静态最终字符串DEFAULT\u final\u VALUE=“bar”;
私有字符串最终值;
公共子属性(){
该值(默认值);
}
@构造绑定
公共anysubperty(@DefaultValue(DEFAULT\u FINAL\u VALUE)字符串finalValue){
this.finalValue=finalValue;
}
}
}

你们非常接近。您只需将@DefaultValue注释添加到字段中,而无需将参数添加到注释中:

public AnyProperties(
      @DefaultValue("foo") String something, 
      @DefaultValue AnySubProperties sub
   ) {
       this.something = something;
       this.sub = sub; // Always null !
   }
这样,您就不需要任何子属性的默认构造函数。剩余的构造函数将用于创建具有默认值的anysubperty实例