You can't. Injection can only happen after an object has been created (or during construction with constructor injection). In other words, when prop.getName()
is called inside the abstract class constructor, the field is still null
since Spring hasn't processed it.
Consider refactoring your code so that your abstract class has a constructor that accepts a Prop
argument and use constructor injection
public AbstractClass(Prop prop) {
this.prop = prop;
prop.getName();
}
...
@Autowired
public DefaultClass(Prop prop) {
super(prop);
}