CXF配置
1.web.xml
配置
<!--Spring MVC是通过DispatcherServlet来加载Spring配置文件的,因此不需要在web.xml中配置ContextLoaderListener。
但是CXF却需要通过ContextLoaderListener来加载Spring。-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置CXF框架的核心Servlet -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/server/*</url-pattern>
</servlet-mapping>
2.spring-webservice.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd"
default-lazy-init="true">
<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
<!--<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />-->
<!--发布webservice-->
<!-- WebService的实现Bean定义 -->
<!--web.xml配置了webservice的访问路径/server/*,那么/server/web-publish?wsdl就是该webservice的访问路径-->
<bean id="webserviceServer" class="com.lida.dream_webservice.server.MyWebserviceImpl" />
<!-- jax-ws endpoint定义 -->
<jaxws:endpoint id="myService" implementor="#webserviceServer" address="/web-publish" >
</jaxws:endpoint>
<!--发布webservice-->
</beans>
3.写一个接口,实现服务类接口
4.客服端接口调用接口地址
5.需要的jar包
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.8</version>
</dependency>
<!--web service 以下都是cxf必备的-->
<!--org.apache.cxf.transport.servlet.CXFServlet-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.8</version>
</dependency>
<!--不加这个包会报错Unable to locate spring NamespaceHandler for XML schema namespace [http://cxf.apache.org/jaxws]-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.8</version>
</dependency>
<!--java实现webservice,不部署到tomcat,需要jetty包支持-->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.1.8</version>
</dependency>