码迷,mamicode.com
首页 > 编程语言 > 详细

springboot配置文件

时间:2019-10-18 09:16:38      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:href   简单   map   get   ref   处理   注意   ring   pac   

@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;
    }
    
}

 

主要对下面两个文档的补充

http://blog.didispace.com/spring-boot-learning-21-1-3/

https://mrbird.cc/Spring-Boot%20basic%20config.html

springboot配置文件

标签:href   简单   map   get   ref   处理   注意   ring   pac   

原文地址:https://www.cnblogs.com/SmilingEye/p/11696368.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!