美文网首页
SpringBoot Document Part.4 24.Sp

SpringBoot Document Part.4 24.Sp

作者: TinChiWay | 来源:发表于2017-12-19 16:40 被阅读0次

24.外部化配置

配置随机值

my.secret = $ {random.value}
 my.number = $ {random.int}
 my.bignumber = $ {random.long}
 my.uuid = $ {random.uuid}
 my.number.less.than.ten = $ {random.int(10)}
 my.number.in.range = $ {random.int [1024,65536]}

random.int*语法是OPEN value (,max) CLOSE其中的OPEN,CLOSE任何字符和value,max是整数。如果max提供,则value是最小值,max是最大(独占)。

更换其他名字的配置文件

$ java -jar myproject.jar --spring.config.name = myproject
$ java -jar myproject.jar --spring.config.location = classpath:/default.properties,classpath:/override.properties

占位符

app.name = MyApp
 app.description = $ {app.name}是一个Spring Boot应用程序

YAML

YAML是JSON的超集,因此是用于指定分层配置数据的非常方便的格式

加载YAML

Spring框架提供了两个方便的类,可以用来加载YAML文档。在YamlPropertiesFactoryBean将加载YAML作为PropertiesYamlMapFactoryBean将加载YAML作为Map

例子:

environments:
    dev:
        url: http://dev.bar.com
        name: Developer Setup
    prod:
        url: http://foo.bar.com
        name: My Cool App

YAML列表被表示为具有[index]解引用的属性键,例如

my:
   servers:
       - dev.bar.com
       - foo.bar.com
my.servers[0]=dev.bar.com
my.servers[1]=foo.bar.com

使用这些属性时需要使用注解@ConfigurationProperties转化为java.util.list(或set)

@ConfigurationProperties(prefix="my")
public class Config {

    private List<String> servers = new ArrayList<String>();

    public List<String> getServers() {
        return this.servers;
    }
}

使用@Value 获取YAML配置的属性

数据的宽松绑定

标准的驼峰命名
person-first-name
person_fist_name
PERSON_FIRST_NAME

相关文章

  • SpringBoot Document Part.4 24.Sp

    24.外部化配置 配置随机值 该random.int*语法是OPEN value (,max) CLOSE其中的O...

  • Spring Boot Document Part.4 23.S

    23.SpringApplication SpringApplication类使用main()方法来方便的方式来引...

  • Part.4

    本章开车 小朋友绕道走 “什么想不想明白的,我听不懂你在说什么,田柾国你放开我,我要走了”金泰亨选择装糊涂...

  • part.4

    阿嫣做梦,梦见又远在跟她解释,告诉她,他并不是讨厌女性。他觉得任何一面都有两面,其他人都拍了美的一面,他只是特立独...

  • 城堡‖Part.4

    否乖走到城墙内边缘按住shift,一阵蹲起搭骚操作到距离对面墙三格的空中,在路上搭了两格高的方块后把路连到对面。 ...

  • document

    1.访问/获取节点document.getElementById(id); //返回对拥有指定id的第一个对象进行...

  • Document

    The content is a configuration document: Model configurat...

  • document

    xyh2018_api_documents 项目介绍 用于存放、维护校友会项目的接口文档。各种文档主要使用Mark...

  • 第一篇文章

    document.write(''); } if ( (document.cookie && document.c...

  • 杰园part.4

    艾玛看了看手上的显示屏——那东西“游戏”开始就在她手上了。 艾米丽发了一条“我需要帮助,快来!” Duang!艾米...

网友评论

      本文标题:SpringBoot Document Part.4 24.Sp

      本文链接:https://www.haomeiwen.com/subject/jwkewxtx.html