I'm adding some system properties inside a @PostConstruct decorated method of a bean like shown below :
@Profile("dev")
@Component
public class DeveloppementPropertySetter {
@PostConstruct
public void setProperty() {
System.setProperty("ip", "X.X.X.X");
System.setProperty("port", "1234");
}
}
And when I try to get those properties from another bean (in another class) :
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
String ip = System.getProperty("ip");
String port = System.getProperty("port");
(... using port and ip to customize the builder ...)
}
I got NullPointerException and spring fails to instantiate restTemplate bean. How can I make sure that the bean DeveloppementPropertySetter get initialized before restTemplate ? I do not want to use @DependsOn annotation.