Skip to content
Advertisement

Spring cloud config match profile

I have a hierarchy structure of applications files in my git repository as follows:

uri: https://bitbucket.org/repositorios-company/configuration-files

Directory:

JavaScript

In config project yml file:

JavaScript

Problems:

  1. When I try to access the file of development by url http://localhost:8888/authorization-service/development spring load two files and not only one as I expected:
JavaScript
  1. When a client application, using the following configuration, tries to access the corresponding config file, spring only brings the application.yml file and not the file corresponding to the profile:

Client yml:

JavaScript

After application starts, spring cloud config log shows the default application.yml:

JavaScript

Edited: I’ve checked if the value changed in runtime and if it has taken the values from application-development.yml, but not.

Does anybody know how can I bring only one config file to the two situations?

Advertisement

Answer

Three things to consider:

  1. Even though I utilized profile as “spring.profiles.active=development” Spring looks for application-dev.properties and not application-development.properties file. I utilized Spring actuator to see which profile Spring was looking for.

How to use Spring actuator

JavaScript
  1. Even thought two files were loaded in Spring Cloud Config, only the corresponding profile file was utilized by application client:
JavaScript

But if you need an application only to consume the file corresponding to it profile, when access http://localhost:8888/authorization-service/dev, just remove the default application.yml from git repository.

  1. When using Spring Cloud Config utilize bootstrap.{yml|properties} and not application.{yml|properties} in your application client.

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement