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

前端 未结 8 808
慢半拍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条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 04:15

    Another use for bootstrap.yml is to load configuration from kubernetes configmap and secret resources. The application must import the spring-cloud-starter-kubernetes dependency.

    As with the Spring Cloud Config, this has to take place during the bootstrap phrase.

    From the docs :

    spring:
      application:
        name: cloud-k8s-app
      cloud:
        kubernetes:
          config:
            name: default-name
            namespace: default-namespace
            sources:
             # Spring Cloud Kubernetes looks up a ConfigMap named c1 in namespace default-namespace
             - name: c1
    

    So properties stored in the configmap resource with meta.name default-name can be referenced just the same as properties in application.yml

    And the same process applies to secrets :

    spring:
      application:
        name: cloud-k8s-app
      cloud:
        kubernetes:
          secrets:
            name: default-name
            namespace: default-namespace
            sources:
             # Spring Cloud Kubernetes looks up a Secret named s1 in namespace default-namespace
             - name: s1
    

提交回复
热议问题