I have a subclass like below:-
@Component
public class Subclass extends Superclass {
//few inherited methods implementation
}
Superclass is like below:-
@Component
public class Superclass implements InterfaceA {
@Autowired
@Qualifier("envBean")
private EnvironmentBean envBean;
private DateTime effective_date = envBean.getProperty("effective.date");
}
Now while deploying the application, I am getting below errors
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name "Subclass"
Constructor threw exception; nested exception is java.lang.NullPointerException
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [Subclass]:Constructor threw exception; nested exception is java.lang.NullPointerException.
and finally I saw -
Caused by: java.lang.NullPointerException: null
at Superclass <init> (SuperClass.java:{lineNumber}
which is at the below line :-
**envBean.getProperty("effective.date");**
I have tried using constructor injection of EnvironmentBean property from the subclass itself Tried configuring it in xml and to instantiate Superclass bean with constructor injection. Does someone have any idea how to resolve it?
Maybe you can try interface -> InitializingBean, and override method 'afterPropertiesSet', then you can assign effective_date value. just like:
@Override
public void afterPropertiesSet() {
effective_date = envBean.getProperty("effective.date");
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments