Difference between Spring Boot configuration files yml and properties

In Spring Boot, there are two different configuration file formats that can be used to configure the application: YAML (YAML Ain’t Markup Language) and Properties.

The differences are as follows:

  1. Grammar format: YAML uses indentation and colons to represent hierarchical structure, while Properties uses key-value pairs format.
  2. YAML example: server:
    port: 8080
    context path: /app
  3. Sample properties:
    – server port is set to 8080
    – server context path is /app
  4. Hierarchy Structure: YAML can easily represent complex hierarchical structures, whereas Properties can only represent simple key-value pairs.
  5. YAML example:
    server:
    port: 8080
    context-path: /app
    datasource:
    url: jdbc:mysql://localhost:3306/mydb
    username: root
    password: password
  6. Example properties:
    server port is set to 8080, server context path is /app, datasource URL is jdbc:mysql://localhost:3306/mydb, datasource username is root, and datasource password is password.
  7. Readability: YAML is more readable than Properties because it uses indentation and line breaks to represent hierarchical structures, while Properties uses periods and equal signs to represent hierarchical structures.
  8. YAML example: server:
    port: 8080
    context-path: /app
  9. Example of Properties:
    server.port=8080
    server.context-path=/app

In conclusion, YAML is generally better for representing complex configurations, especially when the configuration file contains multiple levels of nesting. Meanwhile, Properties is more suitable for representing simple key-value pair configurations. You can choose the appropriate configuration file format based on your own needs.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds