I have an abstract class in which I am trying to use the @Value annotation to inject value from a property file
public abstract class Parent {
@Value ("${shared.val}")
private String sharedVal;
public Parent() {
//perform common action using sharedVal
}
}
@Component
public class ChildA extends Parent {
Param a1;
@Autowired
public ChildA (Param a1) {
super();
this.a1 = a1;
}
}
I am getting NullPointerException since sharedVal is not set. I tried adding @Component stereotype on the abstract class and still the same thing.
Can I inject value into abstract class this way? If not how can accomplish this?