A small summary of Properties/YAML/YML syntax

Let me first talk about the difference between YML, YAML, and Properties:
(1) The writing is different. Properties is similar to: spring.datasource.username = XXX, the other two are indented, the readability properties are more acceptable, but yaml and yml look more concise and elegant.
(2) The loading sequence is different. They are all configuration files. After startup, the Configuration configuration class will read and load the parameters written in it, but the priority order of loading is different. YML has the highest priority, YAML second, and Properties third. Those loaded later will overwrite the ones loaded first.
(3) Yml and yaml have many special grammars and points to note:

1: Be sure to pay attention to indentation! Sometimes very small spaces will report inexplicable errors.
2: A horizontal bar "-" means other elements of the same list. For example, when configuring clusters or microservices, because the key is not allowed to be repeated, if I have multiple server names: XXX, an error will be reported. This time Just write-server name.
3: The three horizontal bars "—" mean to start a new file. If we use properties configuration, we distinguish between dev, local, prod, test. A lot of configuration files are very disgusting. For yaml, all can be written in a yml file , As long as separated by -, it means that it is another file.
Insert picture description here

Guess you like

Origin blog.csdn.net/whiteBearClimb/article/details/109181872