I run the object using spring and I call the method using the same object that was automatically added. This throws a NullPointerException. The problem is that I am calling a method inside a static block. Below is my code -
@Autowired
static MyPropertyManagerClass myPropertyManagerClass;
private static URL SERVICE_URL = null;
static {
try {
SERVICE_URL = myPropertyManagerClass.getServiceURL();
}
catch (Exception e) {
log.error("Exception Occurred While Invoking myPropertyManagerClass.getServiceURL() : " , e);
}
}
If I'm not mistaken, this is because the static block is loaded first. Is there any way I can do this work without creating an object with a new keyword?
source
share