A simple solution for integrating Spring Framework and Axis, allowing the Axis Web Services Engine to use Spring IoC containers and AOP technology. To use SpringProvider, Axis's Server-config.wsdd configuration examples are as follows:
service>
Configure spring ApplicationContext.xml as follows:
beans>
The following is a class structural diagram integrated Spring Framework and Axis engine, you can integrate Axis and other IOC containers (such as PicoContainer) using the same method.
In the above graph, the purple is the original class of Spring framework; the grass green and the sky is the original class of AXIS, with grass green classes need to be modified; only orange is a class that needs to be developed. The following is the code snippet of the SpringProvider class:
Public class SpringProvider Extends rpcprovider {protected static log log = logfactory.getlog (SpringProvider.class.getname ());
Public static final string Option_beanname = "beanname";
protected Object makeNewServiceObject (MessageContext msgContext, String clsName) throws Exception {String beanName = getStrOption (OPTION_BEANNAME, msgContext.getService ()); return getService (beanName, msgContext);}
Protected string getServiceClassNameOptionName () {return option_beanname;}
protected Object getService (String beanName, MessageContext context) throws AxisFault {ApplicationContext appContext = getAppContext (context); if (appContext == null) {log.fatal ( "Spring ApplicationContext is NULL."); throw new AxisFault ( "get Spring ApplicationContext Error. ");
Object bean = appContext.getBean (beanname); if (bean == null) {log.error ("bean named:" beanname "is null"); throw new Axisfault ("bean named:" beanname "IS nULL ");} return bean;} protected String getStrOption (String optionName, Handler service) {String value = null;! if (service = null) value = (String) service.getOption (optionName); if (value == null Value = (String) GetOption (optionname); Return Value;}
protected Class getServiceClass (String beanName, SOAPService service, MessageContext msgContext) throws AxisFault {ConfigurableListableBeanFactory beanFactory = getBeanFactory (msgContext); if (beanFactory == null) {log.error ( "BeanFactory is NULL"); throw new AxisFault ( "BeanFactory is ");} Object bean = beanfactory.getBeandefinition (beanname); return bean.getclass ();
protected XmlWebApplicationContext getAppContext (MessageContext msgContext) {HttpServlet servlet = (HttpServlet) msgContext.getProperty (HTTPConstants.MC_HTTP_SERVLET); ServletContext servletContext = servlet.getServletContext (); XmlWebApplicationContext appContext = (XmlWebApplicationContext) servletContext .getAttribute (WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); return appContext; }