0

My question is about spring boot autoconfiguration and if default propertyvalues can be set depending on which profile is active.

Sometimes the same properties are added in alot of microservices. For example if we depend on a swagger client. Then the endpoint url for all the different environments need to be set in all the projects that use that client. It would be nice if we could set that up in a starterproject for that client. Then there would only be one place where we would have to maintain that.

But the property is not the same in all environments so it should be possible to have a default value per environment. Is there a best way to do this?

Ole Bille
  • 469
  • 2
  • 14

1 Answers1

0

If you are using spring cloud config service, you can arrange your configuration this way:

src/main/resources/
    bootstrap.yml
    bootstrap-profile1.yml
    bootstrap-profile2.yml
    ...
src/main/resources/profile1/
        application.yml
        service1.yml
        service2.yml
        ....
src/main/resources/profile2/
        application.yml
        service1.yml
        service2.yml
        ....  

Where application.yml in each profile folder will have default configurations for each service which can be overridden in configuration file of that service.

bootstrap.yml will look like:

spring:
  application:
    name: config-service
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/profile1,classpath:/profile2,...
  profiles:
    active: native,${CONFIG_ENV}
S.K.
  • 3,597
  • 2
  • 16
  • 31
  • Thx for your answer. Im not that experienced with spring cloud. But this looks normal configurations and not something used when spring runs the autoconfiguration phase of the initialization. – Ole Bille Aug 22 '18 at 07:56
  • I know how I can use configuration in every microservice and it will be loaded by the beans I initialize in the autoconfiguration. But what Id like not to do is to have to add those configurations everytime I need the client. – Ole Bille Aug 22 '18 at 09:04
  • Can you include an example (with code if possible) in the description with details of what you want. It's a bit confusing by just reading the description. Thanks! – S.K. Aug 22 '18 at 09:12