2

How to assign value to variable based on region?

Lets says

system properties, dev-url="dev-abc.com", prod-url="prod-abc.com" and qa-url="qa-abc.com"

@Value( #{systemProperties. ??? )
String url;
Zico
  • 2,349
  • 2
  • 22
  • 25
sash84
  • 85
  • 1
  • 3
  • 8
  • Do you mean you have all these 3 kind of url variable and you want to set String url based on your spring profile? – Zico Jul 20 '17 at 07:36
  • You must have different `.properties` obviously . you can get according to the environment – soorapadman Jul 20 '17 at 07:37

2 Answers2

4

if you have all properties inside on property file you can use :

 @Value("${spring.profiles.active}-url") String url;
xyz
  • 5,228
  • 2
  • 26
  • 35
  • Yes I'm using only one property file and I'm not interested in using 3 property files I tried your below suggestion @Value( #{systemProperties[${spring.profiles.active}'-url'] ) String url; but it is not working.Is any changes required in spel ? – sash84 Jul 21 '17 at 03:39
  • 1
    use @Value("${spring.profiles.active}-url") String url; – xyz Jul 21 '17 at 05:28
1

I would suggest to avoid profiles as much as possible. Modern applications should strive to follow rule 3 of 12 Factor app:

The twelve-factor app stores config in environment variables

With Spring Boot you would have environment variable URL environment variable and use it in Spring Boot as ${URL}. Each environment would have this environment variable configured to correct value.

luboskrnac
  • 23,973
  • 10
  • 81
  • 92