With this class
@Component
public class Sample {
@Value("${my.name}")
public static String name;
}
If I try Sample.name
, it is always 'null'. So I tried this.
public class Sample {
public static String name;
@PostConstruct
public void init(){
name = privateName;
}
@Value("${my.name}")
private String privateName;
public String getPrivateName() {
return privateName;
}
public void setPrivateName(String privateName) {
this.privateName = privateName;
}
}
This code works. Sample.name
is set properly. Is this good way or not? If not, is there something more good way? And how to do it?