Spring Boot升级到2.2.6-无法将yaml属性绑定到对象列表

Spring Boot升级到2.2.6-无法将yaml属性绑定到对象列表,spring,spring-boot,yaml,java-11,Spring,Spring Boot,Yaml,Java 11,我正在将一个项目升级到SpringBoot2.2.6。将yaml属性数据绑定到对象列表时出现以下编译错误- **请注意,该项目是在我使用的SpringBoot(2.2.1)的早期版本中编译的** java.lang.IllegalStateException:未能加载ApplicationContext 原因:org.springframework.boot.context.properties.ConfigurationPropertiesBindException:创建名为“webUiApp

我正在将一个项目升级到SpringBoot2.2.6。将yaml属性数据绑定到对象列表时出现以下编译错误-

**请注意,该项目是在我使用的SpringBoot(2.2.1)的早期版本中编译的**

java.lang.IllegalStateException:未能加载ApplicationContext 原因:org.springframework.boot.context.properties.ConfigurationPropertiesBindException:创建名为“webUiApplication.States”的bean时出错:无法将属性绑定到“webUiApplication.States”:前缀=状态,ignoreInvalidFields=false,ignoreUnknownFields=true;嵌套异常为org.springframework.boot.context.properties.bind.BindException:未能将“states.defaults”下的属性绑定到java.util.List

application.yml

   states:
  defaults:
    -
      postal-code: AL
      name: Alabama
    -
      postal-code: AK
      name: Alaska
    -
      postal-code: AZ
      name: Arizona
配置

    @Data 
   @Configuration
   @ConfigurationProperties("states")
   public static class States {

      private List<State> defaults;

      private List<State> docVerify;

      private List<State> registration;

  }
@数据
@配置
@配置属性(“状态”)
公共静态类状态{
私有列表默认值;
私人名单;
私人名单登记;
}
波乔

@数据
@EqualsAndHashCode(仅限于xplicitlyincluded=true)
@ToString(仅限ExplicitlyIncluded=true)
公共类状态实现ListOption{
public static final Comparator DISPLAY_Comparator=new ListOption.DisplayComparator();
@非空私有最终字符串postalCode;
@非空的私有最终字符串名称;
@凌驾
@EqualsAndHashCode.Include
公共字符串getValue(){
返回此.postalCode;
}
@凌驾
@ToString.包括
公共字符串getLabel(){
返回字符串。格式(“%s-%s”,后代码,名称);
}
}
遇到会员收到类似问题但未能找到解决方案的帖子。期待您的输入。

重构您的代码:

国家:

@Data

    @Configuration
    @ConfigurationProperties("states")
    @ToString
    @NoArgsConstructor
    public class States {
        private List<State> defaults;
        private List<State> docVerify;
        private List<State> registration;

    }
应用程序.yaml

states:
  defaults:
    -
      postal-code: AL
      name: Alabama
    -
      postal-code: AK
      name: Alaska
    -
      postal-code: AZ
      name: Arizona
我们需要有一个空对象,然后用数据填充它。这就是为什么我们不需要args构造函数。

重构代码:

国家:

@Data

    @Configuration
    @ConfigurationProperties("states")
    @ToString
    @NoArgsConstructor
    public class States {
        private List<State> defaults;
        private List<State> docVerify;
        private List<State> registration;

    }
应用程序.yaml

states:
  defaults:
    -
      postal-code: AL
      name: Alabama
    -
      postal-code: AK
      name: Alaska
    -
      postal-code: AZ
      name: Arizona

我们需要有一个空对象,然后用数据填充它。这就是为什么我们不需要args构造函数。

您确定spring boot 2.2.1上使用的代码完全相同吗?是的,它在以前的版本中工作正常,您确定spring boot 2.2.1上使用的代码完全相同吗?是的,它在以前的版本中工作正常,我想问题是为什么它在以前的版本中工作。是什么改变了这个新版本,导致它崩溃?可能添加这些信息会有帮助,我想问题是为什么它在以前的版本中工作。是什么改变了这个新版本,导致它崩溃?可能正在添加此信息将有所帮助