- Web.xml Declarations
We have to declare Spring Context Listener, CXF Servlet, Spring Context Location and URL Mapping.
1: <?xml version="1.0" encoding="UTF-8"?>
2: <web-app id="services" version="2.5"
3: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
4: xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
5: xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
6: http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
7:
8: <!-- Adding the Spring Context Listener. It will help to init Spring Context -->
9: <listener>
10: <listener-class> org.springframework.web.context.ContextLoaderListener
11: </listener-class>
12: </listener>
13:
14: <!-- Context file location of Spring -->
15: <context-param>
16: <param-name>contextConfigLocation</param-name>
17: <param-value>/WEB-INF/applicationContext.xml</param-value>
18: </context-param>
19:
20: <!-- CXF Servlet -->
21: <servlet>
22: <servlet-name>CXFServlet</servlet-name>
23: <servlet-class> org.apache.cxf.transport.servlet.CXFServlet
24: </servlet-class>
25: </servlet>
26:
27: <!-- Mapping with a URL Pattern -->
28: <servlet-mapping>
29: <servlet-name>CXFServlet</servlet-name>
30: <url-pattern>/*</url-pattern>
31: </servlet-mapping>
32: </web-app>
- Application Context configurations
1: <?xml version="1.0" encoding="UTF-8"?>
2: <beans xmlns="http://www.springframework.org/schema/beans"
3: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
4: xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
5: xsi:schemaLocation="http://www.springframework.org/schema/beans
6: http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7: http://www.springframework.org/schema/context
8: http://www.springframework.org/schema/context/spring-context-2.5.xsd
9: http://cxf.apache.org/core
10: http://cxf.apache.org/schemas/core.xsd
11: http://cxf.apache.org/jaxws
12: http://cxf.apache.org/schemas/jaxws.xsd"
13: default-autowire="byName">
14:
15: <!-- Load CXF modules from cxf.jar -->
16: <import resource="classpath:META-INF/cxf/cxf.xml" />
17: <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
18: <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
19:
20: <!-- The service bean -->
21: <bean id="productServiceImpl" class="com.your.company.service.ProductServiceImpl" />
22:
23: <!-- Aegis data binding -->
24: <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding"
25: scope="prototype" />
26: <bean id="aegis-service" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
27: scope="prototype">
28: <property name="dataBinding" ref="aegisBean" />
29: <property name="serviceConfigurations">
30: <list>
31: <bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration" />
32: <bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration" />
33: <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration" />
34: </list>
35: </property>
36: </bean>
37:
38: <!-- Service endpoint -->
39: <jaxws:endpoint id="productService"
40: implementorClass="com.your.company.service.ProductServiceImpl"
41: implementor="#productServiceImpl" address="/productservice">
42: <jaxws:serviceFactory>
43: <ref bean="aegis-service" />
44: </jaxws:serviceFactory>
45: </jaxws:endpoint>
46:
47: <!-- Enable message logging using the CXF logging feature -->
48: <cxf:bus>
49: <cxf:features>
50: <cxf:logging />
51: </cxf:features>
52: </cxf:bus>
53: </beans>
Create a WAR out of this Project and deploy it in Apache Tomcat. And try to access the WSDL URL
http://localhost:8080/CXFExample/ProductService?wsdl.
Other related posts:
1. Creating Web services using Apache CXF (Part 1) : The Basics.
2. Creating Web services using Apache CXF (Part 2) : Development.
3. Creating Web services using Apache CXF (Part 3) : Configuration.
4. Creating Web services using Apache CXF (Part 4): Testing.
15 thoughts on “Creating Web services using Apache CXF (Part 3): Configurations”