CXF实战之在Tomcat中发布Web Service(二)
2015-07-27 15:02
399 查看
服务接口及实现类请参考WebService框架CXF实战(一)
创建Maven Web项目,在pom.xml中添加CXF和Spring Web的引用,由于CXFServlet需要Spring Web的支持。
在WEB-INF下创建cxf-servlet.xml配置文件。
在WEB-INF/web.xml中添加CXFServlet配置,CXFServlet匹配/services路径下的所有请求。
启动Tomcat后,在浏览器中输入http://<网站路径>/cxfserver/services即可看到如下效果,由于这里配置CXFServlet的路径是/services,如果配置其他路径,服务的请求路径也不一样,不过大体上是http://<网站路径>/cxfserver/
创建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/
相关文章推荐
- Intellij IDEA远程调试tomcat
- MyEclipse搭建tomcat服务器过程详解
- Tomcat启动过程
- 视频播放提示:video not found or access denied
- Tomcat 简介
- Linux下Tomcat VM参数修改
- linux下安装tomcat并设置开机自启动
- Eclipse下tomcat输出路径配置
- tomcat部署之字符编码问题
- 【Tomcat】Tomcat报错追踪
- ubuntu下如何整合apache2与tomcat
- Myeclipse配置Tomcat
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules
- nginx结合tomcat使用
- tomcat 启动一闪而过
- Ubuntu12.04以及centos jdk7 32位安装 和设置tomcat监听内网地址
- Tomcat 6 日志输出配置
- 如何在eclipse上创建web项目(tomcat)
- SSL/TLS双向认证实现(JAVA、TOMCAT)
- SSL/TLS单向认证实现(JAVA、TOMCAT)