1

I am working on microservices using spring boot. i have around 5 microservices. so I configured spring cloud config server to centralized configuration. its perfectly working fine.

config server configuretion

spring.profiles.active=native

spring.cloud.config.server.native.search-locations=classpath:/common-config

server.port=8888

now the problem is I have two environment dev and test and i created application-test.properties and application-dev.properties as per the spring documented i need to set profile like

Spring profile

spring.profiles.active=test

but its already set as a native then how can i load multiple profile.

please help me ..

Community
  • 1
  • 1
user3364549
  • 217
  • 2
  • 4
  • 11

3 Answers3

0

You can pass in the active profile name as an environment variable at run time of each of the apps. This will take priority over the active profile listed in your properties file. You can do this with any property actually. If you're using docker to launch your apps, you can pass it in from your Dockerfile or from your docker-compose.yml

Daisy Day
  • 652
  • 7
  • 19
  • yes i tried this but its not getting profile and throwing db url related error – user3364549 Aug 03 '18 at 06:03
  • Hmm ok! Please could you provide an example of how you're passing the environment variables in? Oh and it might be worth moving the profile name to the bootstrap.properties file as it's loaded earlier – Daisy Day Aug 03 '18 at 06:05
  • The examples on https://stackoverflow.com/questions/40981861/how-do-you-properly-set-different-spring-profiles-in-bootstrap-file-for-spring might be useful here – Ryan Dawson Aug 03 '18 at 08:51
0

You can set spring.profiles.active=$ACTIVE_SPRING_PROFILE and set OS environment ACTIVE_SPRING_PROFILE = test

Sann Tran
  • 159
  • 5
0

You can use multiple profiles in Spring. Try:

spring.profiles.active=dev,native

See more: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-profiles.html#boot-features-profiles

nmyk
  • 1,582
  • 1
  • 8
  • 20
  • its throwing me same error "determine embedded database url for database type NONE" (no profiles are currently active) – user3364549 Aug 03 '18 at 07:23
  • You probably didn't provide enough information to auto-configure a DataSource. Or maybe if you are not using database access - you should not add spring-boot-starter-data-jpa to pom (sometimes can be copied there by mistake). Anyway it's hard to guess without source code. – nmyk Aug 03 '18 at 07:42