Tutorial/How to: Using Spring’s context with Apache Axis
The integration of Spring and its context into a JSP (Java Server Pages) based environment like JSP itself or JSF is supported pretty well. But the bridge between Spring and Apache Axis or even other Servlet based frameworks and libraries has often to be build by yourself. This article describes one possible method for integrating Spring into Apache Axis.
For my purposes, it was always okay to integrate Spring into Apache Axis using an abstract backing bean. The following example shows such a bean, which takes Axis’ MessageContext to determine the current ServletContext. Retrieving the MessageContext is the only Axis speciality in this bean. By modifing this speciality, this bean would be able to integrate Spring into every Servlet based environment. You just have to be able to receive a ServletContext object and hand it over to Spring’s WebApplicationContextUtils.getWebApplicationContext(ServletContext). Spring will manage the rest for you
package de.mhsdev.framework.web.springsupport;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import org.apache.axis.MessageContext;
import org.apache.axis.transport.http.HTTPConstants;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
public abstract class AbstractSpringBean {
private ApplicationContext applicationContext;
protected AbstractSpringBean() {
MessageContext messageContext = MessageContext.getCurrentContext();
HttpServlet servlet = (HttpServlet) messageContext
.getProperty(HTTPConstants.MC_HTTP_SERVLET);
ServletContext servletContext = (ServletContext) servlet
.getServletContext();
applicationContext = WebApplicationContextUtils
.getWebApplicationContext(servletContext);
}
public ApplicationContext getApplicationContext() {
return applicationContext;
}
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}
I hope you can use this inspiration and that my bean will help you.
