CXF實戰之在Tomcat中公布Web Service(二)

來源:互聯網
上載者:User

標籤:_id   project   mave   for   輸入   啟動   webapp   tag   ade   

服務介面及實作類別請參考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/

CXF實戰之在Tomcat中公布Web Service(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.