Prabaharan Gopalan wrote:At what point this code gets called? Are you sure that the applicationContext has finished loading by then? This could happen easily if you have Bean A which calls a Util class which tries to get Bean B from Application Context. But, there is always the chance that Bean B hasn't been loaded yet. You might want to explore the Application Context's life cycle to understand how things work before do this.
And did you wire DeferredUnlockerTest.class in your application context? And if you did, what's the issue in injecting that via the usual Spring way instead of ApplicationContextAware and then all the trouble of context.getBean()?
Prabaharan Gopalan wrote:It's still not clear on where you have this code (the two snippets - are they on the same file/different classes, how they're wired, what's your application-context looks like,..) and what you're trying to achieve.
I'd suggest you start with a smaller stand-alone Java application with Spring and have the bare minimum classes and try to achieve what you're trying to do now. That way you know what's going on and even if that doesn't work, you can share it here. (it might not be okay to paste your company's code here, so a prototype would be ideal, if things don't go well).
Prabaharan Gopalan wrote:From the code you've posted, the only place the NPE could occur is at "this." and 'this' being null. Did you see any other error during the context loading period or can you load this bean the last so that we're sure all other beans are loaded before we hit this point?
Mark Spritzler wrote:Well, I get the web related data in my Controller and just pass them as parameters to my Service business layer classes.
Mark
Piyush Mangal wrote:You might set value in ThreadLocal and the get the same in business layer.