Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使用@ConfigurationPropertiesBinding的转换器不适用于复杂源类型(列表、映射等)_Spring_Spring Boot - Fatal编程技术网

Spring 使用@ConfigurationPropertiesBinding的转换器不适用于复杂源类型(列表、映射等)

Spring 使用@ConfigurationPropertiesBinding的转换器不适用于复杂源类型(列表、映射等),spring,spring-boot,Spring,Spring Boot,我需要将application.yml中的数组透明转换为我的应用程序中的特定类型。我想使用 @ConfigurationPropertiesBinding,但转换器(SimpleConverter)仅适用于简单的源类型。为什么模拟(ComplexConverter)不适用于复杂源类型 独立示例: package.com.example; 导入org.junit.jupiter.api.Assertions; 导入org.junit.jupiter.api.Test; 导入org.springfr

我需要将application.yml中的数组透明转换为我的应用程序中的特定类型。我想使用
@ConfigurationPropertiesBinding
,但转换器(
SimpleConverter
)仅适用于简单的源类型。为什么模拟(
ComplexConverter
)不适用于复杂源类型

独立示例:

package.com.example;
导入org.junit.jupiter.api.Assertions;
导入org.junit.jupiter.api.Test;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.boot.SpringBootConfiguration;
导入org.springframework.boot.context.properties.ConfigurationProperties;
导入org.springframework.boot.context.properties.ConfigurationPropertiesBinding;
导入org.springframework.boot.context.properties.EnableConfigurationProperties;
导入org.springframework.boot.test.context.SpringBootTest;
导入org.springframework.context.annotation.ComponentScan;
导入org.springframework.core.convert.converter.converter;
导入org.springframework.stereotype.Component;
导入java.util.List;
@春靴测试
@SpringBoot配置
@组件扫描(“com.example”)
@EnableConfigurationProperties(ConfBean.class)
公共类ComplexConverterTest{
@自动连线
私有ConfBean ConfBean;
@试验
公开无效测试(){
assertEquals(2*2,confBean.getSimple().getPowValue());//工作
//在我采取行动之后
assertEquals(2,confBean.getComplex().getLeft());
assertEquals(3,confBean.getComplex().getLeft());
}
}
类SimpleVal{
私人最终价值;
SimpleVal(int-powValue){
this.powValue=powValue;
}
public int getPowValue(){
返回值;
}
}
@组成部分
@配置属性绑定
类SimpleConverter实现转换器{
@凌驾
公共SimpleVal转换(整数源){
返回新的SimpleVal(source*source);
}
}
@组成部分
@配置属性绑定
类ComplexConverter实现转换器{
@凌驾
公共ComplexVal转换(列表源){
返回新的ComplexVal(source.get(0),source.get(1));
}
}
类ComplexVal{
左二等兵;
私权;
ComplexVal(左整数,右整数){
this.left=左;
这个。右=右;
}
公共int getLeft(){
左转;
}
public int getRight(){
返还权;
}
}
@配置属性(“conf”)
类ConfBean{
私人单纯形;
私人综合体;
公共SimpleVal getSimple(){
回归简单;
}
public void setSimple(SimpleVal simple){
这个。简单=简单;
}
public ComplexVal getComplex(){
回归情结;
}
公共void setComplex(ComplexVal complex){
这个复杂的=复杂的;
}
}
它是可编译/可执行的

我的申请书

conf:
简单:2
综合体:[2,3]
谢谢你的关注