CXF实战之在Tomcat中公布Web Service(二)
服务接口及实现类请參考WebService框架CXF实战(一)
创建Maven Web项目,在pom.xml中加入CXF和Spring Web的引用,因为CXFServlet须要Spring Web的支持。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rvho</groupId>
<artifactId>cxfserver</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!-- CXF版本号 -->
<cxf.version>3.1.1</cxf.version>
</properties>
<dependencies>
<!-- CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- End CXF -->
<!-- 因为CXFServlet须要Spring Web的支持 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.7.RELEASE</version>
</dependency>
</dependencies>
</project>
在WEB-INF下创建cxf-servlet.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"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:server id="helloWSServer" serviceClass="com.rvho.cxfserver.ws.HelloWS" address="/hello">
<jaxws:serviceBean>
<bean class="com.rvho.cxfserver.ws.impl.HelloWSImpl" />
</jaxws:serviceBean>
</jaxws:server>
</beans>
在WEB-INF/web.xml中加入CXFServlet配置,CXFServlet匹配/services路径下的全部请求。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>cxfserver</display-name>
<!-- CXF Servlet -->
<servlet>
<servlet-name>cxfservlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cxfservlet</servlet-name>
<!-- 匹配/services下的全部请求 -->
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<!-- End CXF Servlet -->
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
启动Tomcat后。在浏览器中输入http://<站点路径>/cxfserver/services就可以看到例如以下效果,因为这里配置CXFServlet的路径是/services,假设配置其它路径,服务的请求路径也不一样。只是大体上是http://<站点路径>/cxfserver/
相关文章
- 坑爹的myeclipse 的tomcat 重部署 redeploy !
- IntelliJ IDEA 14.x 与 Tomcat 集成,创建并运行Java Web项目
- docker 安装tomcat 镜像
- 真正解决问题:maven eclipse tomcat java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
- eclipse3.4配置的tomcat server如何部署以前的web项目?
- Tomcat 第六篇:类加载机制
- 同一个tomcat下面放多个项目 每个项目用不同的域名访问
- 最新整合maven+SSM+Tomcat 实现注册登录
- Eclipse中的Web项目无法自动部署到Tomcat
- Tomcat windows下安装
- 图解Tomcat类加载机制(阿里面试题)
- Tomcat部署的时候 unpackWARs="true"
- Tomcat卷三---Jasper引擎
- 更改自身web项目的图标(默认为tomcat的小喵咪)
- Tomcat通过配置一个虚拟路径管理web工程
- Centos 安装Tomcat
- 008-插件方式启动web服务tomcat,jetty
- 【云原生 | 23】Docker运行Web服务实战之Tomcat
- 软件测试如何快速搭建测试环境:docker 部署 tomcat 环境
- 从零开始手写Tomcat的教程11节----StandardWrapper
- 【手写Tomcat】6.实现自己定义的MyHttpResponse
- 【手写Tomcat】2.实现游览器和服务器的简单通信
- tomcat Context容器(中):Tomcat如何隔离Web应用?