0

using latest Spring 5 on Java 9....

With the following YAML:

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

With Environment the nested property values can be pulled as usual (env.getProperty("flow[0].name") to a string). But how do I pull the flow list into an List<Flow>?

Assuming I need a ConfigurationProperties that maps to a Flow class. Don't want to prefix flow in the yaml.

Then via Environment what would the call to getProperty look like (e.g. env.getProperty("flow", List.class) but with the generic List<Flow> reference). As an aside, the reason I want the list of flows is to register beans after the environment is setup (i.e. EnvironmentPostProcessor) with the individual flow configuration.

Matthew Campbell
  • 1,864
  • 3
  • 24
  • 51

1 Answers1

1

This should work. Give it a try.

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

  List<Flow> flow;
}

@Getter
@Setter
public class Flow {

  public String name;
  public String url;
}
pvpkiran
  • 25,582
  • 8
  • 87
  • 134
  • @pypkiran Didn't know about lombok. Thanks. Setup worked and I autowired in the "Configclass" to get at the "Flow" list. Still wondering how to cast from env.getProperty to a generic list? – Matthew Campbell Jan 10 '18 at 11:53