Eduardo
Eduardo

Reputation: 2279

Spring initializing the @Value annotation property from a static field

Having the following code:

public class Constants {
    public static final String X = "-";
}

And in another class

@Value("${some.property:Constants.X")
private String separator;

How can I achieve this? Constant property is not being loaded

Upvotes: 3

Views: 48

Answers (1)

Ryuzaki L
Ryuzaki L

Reputation: 40078

You need to use the T operator with the actual package name where your Constants class is located like below

@Value("#{T(your.package.Constants).X}")
private String separator;

Upvotes: 4

Related Questions