1

I have a below setup

@Service
public class TestDispatcherImpl implements Dispatcher <MobilePushNotification> {

    @Autowired
    private A a;

    @Autowired
    private B b;

    @Autowired
    private C c;


    @PostConstruct
    public void initialize() {} {
     b.someMethod(); //GETTING A NULL POINTER EXCEPTION, 
                     //in fact all the beans are null

    }
}

public interface Dispatcher <T extends Notification> {

}

What is happening ?

Jonathan
  • 20,053
  • 6
  • 63
  • 70
user883275
  • 79
  • 4

2 Answers2

4

Try removing the extra curly-braces:

public void initialize() {} {
                         ^^
 b.someMethod(); //GETTING A NULL POINTER EXCEPTION, 
                 //in fact all the beans are null

}

I suspect the initializer block, where you call b.someMethod(), is invoked prior to Spring wiring the dependencies. Therefore b is null at this point.

Jonathan
  • 20,053
  • 6
  • 63
  • 70
0

try to handle it using the context:

simple to use this interface

org.springframework.beans.factory.config.BeanPostProcessor

Tiago Medici
  • 1,944
  • 22
  • 22