在Java 9上使用最新的Spring 5.
与下列YAML:
flow:
- name: cats
url: http://dogs.com
- name: dogs
url: http://cats.com使用Environment,嵌套的属性值可以像往常一样被提取(env.getProperty("flow[0].name")到一个字符串)。但是如何将flow列表拉到List<Flow>中?
假设我需要一个映射到ConfigurationProperties类的Flow。不想在yaml中前缀flow。
然后,通过Environment,对getProperty的调用会是什么样子(例如,env.getProperty("flow", List.class),但是有通用的List<Flow>引用)。顺便说一句,我想要flow列表的原因是,在环境设置(即EnvironmentPostProcessor)之后,用单独的流配置注册bean。
发布于 2018-01-10 11:23:57
这应该能行。试试看。
@Configuration
@ConfigurationProperties
@Getter
@Setter
public class Configclass {
List<Flow> flow;
}
@Getter
@Setter
public class Flow {
public String name;
public String url;
}https://stackoverflow.com/questions/48186080
复制相似问题