javaspringspring-mvcspring-properties

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


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 ?


Solution

  • 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.