What is the difference between putting a property on application.yml or bootstrap.yml in spring boot?

前端 未结 8 806
慢半拍i
慢半拍i 2020-12-02 03:13

What is the difference between putting a property on application.yml or bootstrap.yml in spring boot? In logging.config case, the application works different.

8条回答
  •  猫巷女王i
    2020-12-02 04:13

    bootstrap.yml or bootstrap.properties

    It's only used/needed if you're using Spring Cloud and your application's configuration is stored on a remote configuration server (e.g. Spring Cloud Config Server).

    From the documentation:

    A Spring Cloud application operates by creating a "bootstrap" context, which is a parent context for the main application. Out of the box it is responsible for loading configuration properties from the external sources, and also decrypting properties in the local external configuration files.

    Note that the bootstrap.yml or bootstrap.properties can contain additional configuration (e.g. defaults) but generally you only need to put bootstrap config here.

    Typically it contains two properties:

    • location of the configuration server (spring.cloud.config.uri)
    • name of the application (spring.application.name)

    Upon startup, Spring Cloud makes an HTTP call to the config server with the name of the application and retrieves back that application's configuration.

    application.yml or application.properties

    Contains standard application configuration - typically default configuration since any configuration retrieved during the bootstrap process will override configuration defined here.

提交回复
热议问题