SpringBoot case-configuration file-yml configuration file

configuration format

  • SpringBoot provides a variety of property configuration methods
    • application.properties
    • application.yml
    • application.yaml
  • Comparison of Common Configuration File Formats
    • XML (bloated)
      • <configuration>
          <database>
            <host>localhost</host>
            <port>3306</port>
            <username>admin</username>
            <password>password123</password>
          </database>
        </configuration>
        
    • properties (hierarchical structure is not clear enough)
      • database.host=localhost
        database.port=3306
        database.username=admin
        database.password=password123
        
    • yml/yaml ( concise, data-centric, recommended )
      • database:
          host: localhost
          port: 3306
          username: admin
          password: password123
        

yml

basic grammar

  • Case Sensitive
  • There must be a space before the value , as a separator
  • Use indentation to represent hierarchical relationships. When indenting, tab keys are not allowed, only spaces can be used (idea will automatically convert tabs to spaces)
  • The number of spaces indented is not important, as long as the elements of the same level are left-aligned
  • # Indicates a comment, from this character to the end of the line, it will be ignored by the parser

yml data format

  • Object/Map collection
    • user
          name:zhangsan
          age:20
          password:123
  • Array/List/Set collection
    • hooby:
          - java
          - game
          - sport

yml configuration

  • Replace the original properties configuration file

 

Guess you like

Origin blog.csdn.net/weixin_64939936/article/details/132476040