SpringBoot configuration file-SpringBoot (2)

Types and roles of Spring configuration files

  SpringBoot is based on conventions, so many configurations have default values, but if you want to replace the default configuration with your own configuration, you can use application.properties or application.yml (yaml) for configuration.

  SpringBoot will load application.properties or application.yml (yaml) files from the Resources directory by default.

  The application.properties file is a key-value file.

  

What is the application.yml configuration file?

  The yml file format is a file format written by yaml, which is an intuitive data serialization format that can be recognized by a computer, and is easy to read by humans and easy to interact with scripting languages.

  The yml file can be imported by different programming language programs that support the yaml library. The yml file is based on data, which is more concise than the traditional xml method.

  The extension of yml file can use .yml or .yaml

 

Syntax of yml configuration file

  Configure common data

    Syntax: key: value

name: zhangsan

 

  Configure object data

    Syntax: key:

        key1: value1

        key2: value2

    Or: key: {key1: value1, key2: value2}

    Note: The number of spaces in front of key1 is not limited. In yml syntax, the same indentation represents the same level.

    Configure Map data as above.

person: 
    name: zhangsan
    age: 10
    addr: nic

#或者 
person: {name: zhangsan,age: 10,addr: nic}

 

  Configuration (List, Set) data

    Syntax: key: 

        - value1

        - value2

    Or: key: [value1, value2]

City: 
     - Beijing 
     - Tianjin 
     - Shanghai 
     - Chongqing 

# or City: [Beijing, Tianjin, Shanghai, Chongqing] 

# collection element is an object in the form of 
Student:
     - name: zhangsan 
      Age: 18 is  
      Score: 100  
    - name: Lisi 
      Age: 28  
      score: 88  
    - name: wangwu 
      age: 38  
      score: 90    

 

Guess you like

Origin www.cnblogs.com/guancangtingbai/p/12669510.html