yml and properties
In fact, yml and properties files have the same principle, and there are either yml or properties on a project, and either option is to choose one of them.
It is recommended to use yml, which is more concise.
bootstrap and application
1. Loading order
Here we mainly explain the loading order of application and bootstrap.
•bootstrap.yml (bootstrap.properties) load first
•Application.yml(application.properties) loaded
bootstrap.yml is used for bootstrap phases of the application context.
bootstrap.yml is loaded by the parent Spring ApplicationContext.
The parent ApplicationContext is loaded before using application.yml.
2. Configuration differences
Both bootstrap.yml and application.yml can be used to configure parameters.
•bootstrap.yml can be understood as some parameter configurations at the system level, and these parameters generally do not change.
•application.yml can be used to define application level. If you use the files defined in application.yml with spring-cloud-config, you can dynamically replace them.
When using Spring Cloud Config Server, you should specify in bootstrap.yml:
spring.application.namespring.cloud.config.server.git.uri
3. Some encrypted/decrypted information
Example:
bootstrap.ymlspring: application: name: service-a cloud: config: uri: http://127.0.0.1:8888 fail-fast: true username: user password: ${CONFIG_SERVER_PASSWORD:password} retry: initial-interval: 2000 max-interval: 10000 multipleer: 2 max-attempts: 10When using Spring Cloud, "real" configuration data is usually loaded from the server. In order to get the URL (and other connection configurations, such as passwords, etc.), you need an earlier or "bootstrap" configuration. So you put the configuration server property in bootstrap.yml, which is used to load the actual configuration data (usually overriding what is in application.yml [if present]).
Of course, in some cases, you don’t need to distinguish between these two files. You just need to use the application file and write all the options here. The effect is basically the same, regardless of the above load order override.
Summarize
The above is the difference between application.yml and bootstrap.yml in Spring Boot introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!