事实证明它确实有效。但是,似乎您必须使用配置属性,因为简单
@Value("${prop}")似乎在后台使用了不同的路径。(有一些提示,DataBinder在这个secion。不知道是否有关。)
application.properties
foo.bar[0]="a"foo.bar[1]="b"foo.bar[2]="c"foo.bar[3]="d"
并在代码中
@Component@ConfigurationProperties(prefix="foo")public static class Config { private final List<String> bar = new ArrayList<String>(); public List<String> getBar() { return bar; }}@Componentpublic static class Test1 { @Autowired public Test1(Config config) { System.out.println("######## @ConfigProps " + config.bar); }}结果是
######## @ConfigProps ["a", "b", "c", "d"]
而
@Componentpublic static class Test2 { @Autowired public Test2(@Value("${foo.bar}") List<String> bar) { System.out.println("######## @Value " + bar); }}结果是
java.lang.IllegalArgumentException: Could not resolve placeholder 'foo.bar' in string value "${foo.bar}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(... ...


