I am currently in Spring Hell in trying to determine why an @Autowired instance of ApplicationContext is not being injected or is null in the target class for some JUnit tests. The class referencing the ApplicationContext variable is annotated as a @Component and other @Component classes in the same package are being wired properly with different variables. I have tried adding log4j debugging but I end up with a ridiculous amount of output that is not even possible to wade through.
I am wondering if anyone can point me in the direction of the Spring package and classes that do the autoscanning so that I can try to step through the Spring code and see why the class is silently ignored. I have not found a good entry point to start the debugging effort and I am really tired of trial and error in trying to resolve this.
Any suggestions appreciated.
This is a workaround and not a complete answer as I am still looking for a way to debug autoscanning. However, for others who run into this, what I ended up doing is retaining my ApplicationContext in a static variable within the class that later needs it.
While playing around and debugging, I noticed that setApplicationContext from the ApplicationContextAware interface would get called but only at the start of my JUnit tests so I retained it for later use. This is a bit of kludge, but barring a good solution, this is what I have chosen go with for now. We'll see if it bites me later.