codependent
codependent

Reputation: 24442

Spring Boot + Spring Cloud Config - How to add more profiles from the Git external configuration

I have this configuration in a spring boot application:

spring:
  application:
    name: my-app
  profiles:
    active: ${ENVIRONMENT}
  cloud:
    config:
     uri: http://localhost:8888

My config server reads the following files:

my-app-dev.yaml

prop: dev property

my-app-pro.yaml

prop: pro property.

I launch the spring boot app setting -DENVIRONMENT=dev, loading correctly the dev external Git properties.

When I inject the Environment in let's say a controller and do env.getActiveProfiles() I get "dev" as expected.

I would like to add more profiles from the git configuration. For instance:

my-app-dev.yaml

prop: dev property
spring:
  active:
    profiles: dev,business1

my-app-pro.yaml

prop: dev property
spring:
  active:
    profiles: pro,business2

So that env.getActiveProfiles() returns ["dev","business1"]. However what it returns is the initial "dev".

How could this be done?

UPDATE:

As suggested by Dave Syer I tried using spring.profiles.include in the Git files but the new profiles aren't added to the Environment:

my-app-dev.yaml

prop: dev property
spring:
  profiles:
    include: business1

my-app-pro.yaml

prop: dev property
spring:
  profiles:
    include: business2

environment.getActiveProfiles() ---> "dev"

Upvotes: 2

Views: 4453

Answers (1)

Macdao
Macdao

Reputation: 194

Update your spring-boot to 1.5.4.

I tested the same case on my Mac, I found that spring with different version behaves different.

When I'm using Spring Boot 1.3.8.RELEASE with Spring Cloud Brixton.SR7, I got the [dev] profile as active profile(also with Spring Boot 1.4.5.RELEASE)

When I'm using Spring Boot 1.5.4.RELEASE with Spring Cloud Dalston.SR1, I got the [business1, dev] profile as active profile

So I believe it is a bug in Spring Boot 1.3.x and 1.4.x

Upvotes: 2

Related Questions