sash84
sash84

Reputation: 105

Setting variable value based on spring profile

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;

Upvotes: 2

Views: 13819

Answers (2)

xyz
xyz

Reputation: 5407

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

 @Value("${spring.profiles.active}-url") String url;

Upvotes: 5

luboskrnac
luboskrnac

Reputation: 24561

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.

Upvotes: 1

Related Questions