Using @Value with condition in spring in order to map value to string

USer22999299 picture USer22999299 · May 10, 2016 · Viewed 7.9k times · Source

I have a application.properites file with the following:

xxx.xxx = sandbox
xxx.sandbox = 123
xxx.production = 456

I would like to map to a string value 123 in case xxx.xxx == sandbox and 456 in case xxx.xxx == production

...
public class temp { 

 @Value("${??????}")
    private String token;
}

is it possible to fill in a condition incited of the ?????? that will map the token to 123 or 456 according to xxx.xxx ?

Answer

USer22999299 picture USer22999299 · May 14, 2016

A simple way in case someone will hit this question:

@Value("#{'${xxx.xxx}'=='sandbox' ? '${xxx.sandbox}' : '${xxx.production}'}")

I just think it is much easier that start working with profiles.