How do you properly set different Spring profiles in bootstrap file (for Spring Boot to target different Cloud Config Servers)?

前端 未结 3 1927
天命终不由人
天命终不由人 2020-12-30 01:51

We have different config servers per environment. Each spring boot application should target its corresponding config server. I have tried to achieve this by setting profil

3条回答
  •  清歌不尽
    2020-12-30 02:18

    I solved a similar problem with an environment variable in Docker. 
    

    bootstrap.yml

    spring:
      application:
        name: dummy_service
      cloud:
        config:
          uri: ${CONFIG_SERVER_URL:http://localhost:8888/}
          enabled: true
      profiles:
        active: ${SPR_PROFILE:dev}
    

    Dockerfile

    ENV CONFIG_SERVER_URL=""
    ENV SPR_PROFILE=""
    

    Docker-compose.yml

    version: '3'
    
    services:
    
      dummy:
        image: xxx/xxx:latest
        restart: always
        environment:  
          - SPR_PROFILE=docker
          - CONFIG_SERVER_URL=http://configserver:8888/
        ports:
          - 8080:8080
        depends_on:
          - postgres
          - configserver
          - discovery
    

提交回复
热议问题