0

在 Java 9 上使用最新的 Spring 5 ....

使用以下 YAML:

flow:
  - name: cats
    url: http://dogs.com
  - name: dogs
    url: http://cats.com

使用Environment嵌套属性值可以像往常一样拉出(env.getProperty("flow[0].name")到字符串)。但是我如何将列表拉入一个List<Flow>

假设我需要一个ConfigurationProperties映射到一个Flow类。不想在 yaml 中添加流前缀。

然后通过Environment调用getProperty看起来像什么(例如env.getProperty("flow", List.class),但使用通用List<Flow>参考)。顺便说一句,我想要流列表的原因在设置环境(即 EnvironmentPostProcessor)后使用单独的配置注册 bean。

4

1 回答 1

1

这应该有效。试试看。

@Configuration
@ConfigurationProperties
@Getter
@Setter
public class Configclass {

  List<Flow> flow;
}

@Getter
@Setter
public class Flow {

  public String name;
  public String url;
}
于 2018-01-10T11:23:57.243 回答