PDA

View Full Version : How to obtain Application Context from web


zosoo7
Mar 19th, 2006, 07:38 PM
I'm new to Spring as you can see from this question, and I appologize if this question is all over the forum, I couldn't find it. I am using XFire to expose my web services. These are not managed by Spring. I have set up my web.xml (Tomcat) to point to my ApplicationContext.xml file, and set up the listener. How to I obtain the app context in my source code, which is not servlet aware? Thanks.

kenevel
Mar 20th, 2006, 11:38 AM
Hi zosoo7,

It's not straightforward, as far as I know, to retrieve the ApplicationContext unless you've got some object that somehow references the ServletContext.

As an idea, though how does (ab)using Tomcat's read-only JNDI registry and registering an object capable of having the ApplicationContext set on it (or better still, one which is web-app aware and can maintain distinct ApplicationContext objects for multiple web-apps)?

Mike

cmaxwell76
Mar 28th, 2006, 12:54 PM
See this post...

http://forum.springframework.org/showthread.php?t=21712&highlight=axis2

Basically you have to implement the ApplicationContextAware interface.

laenzlinger
Mar 28th, 2006, 01:54 PM
With Axis 1.3 we are using the ServletEnpointSupport class.

Axis implements the JAX-RPC spec and therefore calls the init() method of this class. From then on you have access to the WebApplication context.

In the onInit() method (which is called from init) we set up references to our service layer.

I don't know if this would help in your case, but it works perfectly with our Axis web services.

Christof

http://static.springframework.org/spring/docs/1.2.x/api/org/springframework/remoting/jaxrpc/ServletEndpointSupport.html