Set profile on bootstrap.yml in spring cloud to target different config server

后端 未结 1 1485
太阳男子
太阳男子 2021-02-07 09:04

I use docker compose to run all my micro services. For each service I give it a short hostname.

version: \'2\'

services: 
  config:
    image: springbox-config-         


        
1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-07 09:13

    I find the solution. Basically, we use spring profile to enrich the bootstrap file. For example

    spring:
      application:
        name: myservice
      cloud:
        config:
          uri: http://config:8890
          fail-fast: true
    
    ---
    spring:
      profiles: development
      cloud:
        config:
          uri: http://localhost:8890
    

    The good news is that we don't have to rewrite all properties in a profile. The default properties are inherited. For instance, when the development profile is enabled, my application name is inherited from the default one called always myservice.

    To activate the profile, start the service with the following property

    -Dspring.profiles.active=development
    

    0 讨论(0)
提交回复
热议问题