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

Specifying different profiles in a single file is only support for YAML files and doesn't apply to property files. For property files specify an environment specific bootstrap-[profile].properties to override properties from the default bootstrap.properties.

So in your case you would get 4 files bootstrap.properties, bootstrap-prod.properties, bootstrap-stage.properties and bootstrap-dev.properties.

However instead of that you could also only provide the default bootstrap.properties and when starting the application override the property by passing a -Dspring.cloud.config.uri=<desired-uri> to your application.

java -jar <your-app>.jar -Dspring.cloud.config.uri=<desired-url>

This will take precedence over the default configured values.


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