spring - Injecting property using @Value to abstract class -
i have abstract class in trying use @value annotation inject value 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 getting nullpointerexception since sharedval not set. tried adding @component stereotype on abstract class , still same thing. can inject value abstract class way? if not how can accomplish this? i think you'll find sharedval is being set, you're trying use in constructor. constructor being called (must called) before spring injects value using @value annotation. instead of processing value in constructor, try @postcontruct method instead, eg: @postconstruct void init() { //perform common action using sharedval } (or altern...