springboot配置文件
@ConfigurationProperties(prefix="spring.my-example")
注意一定要写get/set否则获取不到值
@Value只能处理数字、字符串这种简单值
虽然@Value可以处理list
url: http://example.com, http://example.com
@Value("${spring.my-example.url}") public List<String> url;
也可以处理map
foo: "{key1: 'value1', key2: 'value2'}"
@Value("#{${spring.my-example.foo}}") public Map<String,String> maps;
但是这种方式不友好
一般list和map这样写
spring: my-example: url: - http://example.com - http://example.com map: key1: a key2: b
@Configuration @ConfigurationProperties(prefix = "spring.my-example") public class Params { private List<String> url; private Map<String,String> map; public List<String> getUrl() { return url; } public void setUrl(List<String> url) { this.url = url; } public Map<String, String> getMap() { return map; } public void setMap(Map<String, String> map) { this.map = map; } }
主要对下面两个文档的补充
posted on 2019-10-18 09:04 SmilingEye 阅读(167) 评论(0) 编辑 收藏 举报