I am currently working on a project that is based on spring MVC, this is just a standard project using the spring MVC template. so i have web.xml and servlet-context.xml.
I am working on adding Apache cxf web services to this project and encounter some problems when sharing services with existing spring MVC.
My initial approach was to make web services work, so here my web.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml /WEB-INF/spring/jaxwsServlet/jaxwsServlet-context.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>jaxws</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>jaxws</servlet-name> <url-pattern>/industryAspectWS</url-pattern> </servlet-mapping> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
and my jaxwsServlet-context.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:context="http://www.springframework.org/schema/context" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://jax-ws.dev.java.net/spring/core classpath:spring-jax-ws-core.xsd http://jax-ws.dev.java.net/spring/servlet classpath:spring-jax-ws-servlet.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" > <wss:binding url="/industryAspectWS"> <wss:service> <ws:service bean="#industryAspectWS"/> </wss:service> </wss:binding> <bean id="industryAspectWS" class="com.example.ws.IndustryAspectWS"></bean> <context:component-scan base-package="com.example" /> <beans:import resource="../HibernateTransaction.xml" /> <beans:import resource="../JaxbMarshaller.xml" /> </beans>
I copied the context: component-scan beans: import sections from servlet-context.xml
This configuration works fine, as I was able to load the server and call web services, as well as access to servlets and jsp. However, I noticed that since I was quoting hibernateTransaction.xml in both context XML files, there are two session factories.
I want to share all services (such as hibernation) between Apache cxf and spring MVC controllers, so I tried to set the settings in root-context.xml, this did not work. I also tried searching the Internet, but did not find any examples for shared services. Is it possible that we can set a parameter for the exchange of services between the two?
===================================================
I experimented with some settings after I posted this and decided that if I put the lines
<context:component-scan base-package="com.example" />
and
<tx:annotation-driven transaction-manager="txManagerExample" />
both in servlet-context.xml and in jaxwsServlet-context.xml, it will work fine. all other settings can be in the general root context. xml