I am facing this problem: I have a class with a @Value variable declared as static as it is shown. When my application starts the @PostConstruct execution access to a method of this class find my variable with a null value.
If I call to this class after de @PostConstruct execution I can see that the @Value static variable is not null and it has the correct value.
How could I have this variable with its real value in the @PostConstruct execution?
This is my code:
@Component
public class ValidacionesUtils {
public static String variable;
@Value("${access.to.my.variable}")
public void setVariable(String variable) {
this.variable = variable;
}
@PostConstruct
private void init() {
if (variable==null) {
log.error("This is what my application prints");
} else {
log.error("This is not printed");
}
}
}