Back Forum Reply New

calling beans defined in action-servlet.xml

Hello,

I'm using AppFuse example application.
I'm trying to call a bean defined in action-servlet.xml in StartupListener.java.
Unfortunately I receive nullPointerException: .NoSuchBeanDefinitionException: No bean named 'myBean' is definedThe example StartupListener is referencing to beans defined in applicationContext-service.xml and it works fine, but how can I use beans defined in action-servlet.xml?

As attachement is two files concerned. Those 2 files are from Appfuse exmaple application that I have modified.

did you add in web.xml dispatcherservler and ContextLoaderListener ?

You cannot access beans defined in the servet from a Listener. (Although you might get some access depending on your servlet container). Listeners are instantiated BEFORE servlets so lifecycle technical speaking servlets might not yet be available.

The only thing you can do is access beans from the Root context (i.e. ContextLoaderListener loaded beans).


Originally Posted by duarditodid you add in web.xml dispatcherservler and ContextLoaderListener ?

That was my mistake. I added this and now it works! Thanks.
¥
Back Forum Reply New