使用 CXF 整合 Spring 開發 Web Service
CXF和sping具有很好的結合性,所以CXF是Java 程式設計師開發web service最佳的選擇,本文是一個入門的例子,基本是Writing a service with Spring 的一個拷貝,希望能給那些不想去倒騰CXF官方例子的同仁一點幫助,
服務端的開發步驟:
1、新建maven工程,在pom.xml中新增相應的依賴。
2、定義pojo, 見User
3、定義SPE, 見HelloWorld.java
4、實現服務,見HelloWorldImpl.java
5、配置spring上下文,見applicationContext.xml
6,部署到web 容器,比如tomcat。
客戶端的開發步驟
1、新建maven工程,在pom.xml中新增相應的依賴。
2、將服務端的pojo類和SPE拷貝過來,保持包名一致。
3、配置spring上下文,見applicationContext.xml
4、建立ClassPathXmlApplicationContext 進行測試。
記錄下有用的點:
1、cxf預設使用的是Java SE Logging 日誌框架,要想使用log4j, 需要在classpath中新增log4j.properties檔案和提供”-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger“jvm 引數,如圖:
2、在web.xml中宣告CXFServlet 的url-pattern時,最好不要對映成根路徑,比如”/services/*”,這樣所有的web service服務都部署在一個統一的路徑中,而”/services”成為路徑的一部分。
3、當使用soap協議時,使用jaxb框架來進行Java 類和xml 轉換的,所以加上@XmlRootElement 註解。
DEMO下載:test-cxf.zip
相關文章
- CXF開發及與Spring整合開發Spring
- Cxf - Spring整合Cxf暴露WebServicesSpringWeb
- Apache CXF實現Web Service(5)—— GZIP使用ApacheWeb
- CXF--整合SpringSpring
- Cxf - Spring整合呼叫WebServicesSpringWeb
- How to access a remote web service by Camel CXF endpointREMWeb
- 使用CXF與Spring整合實現RESTFul WebServiceSpringRESTWeb
- Apache CXF實現Web Service(4)——Tomcat容器和Spring實現JAX-RS(RESTful) web serviceApacheWebTomcatSpringREST
- 使用apache CXF開發第一個Web服務ApacheWeb
- WebService之Spring+CXF整合示例WebSpring
- 基於Maven的Spring整合CXFMavenSpring
- Spring3.2 + cxf1.7.3整合Spring
- Apache CXF實現Web Service(1)——不借助重量級Web容器和Spring實現一個純的JAX-WS web serviceApacheWebSpring
- Apache CXF實現Web Service(2)——不借助重量級Web容器和Spring實現一個純的JAX-RS(RESTful) web serviceApacheWebSpringREST
- Apache CXF 與 Spring 整合簡單例子ApacheSpring單例
- Apache CXF實現Web Service(3)——Tomcat容器和不借助Spring的普通Servlet實現JAX-RS(RESTful) web serviceApacheWebTomcatSpringServletREST
- 使用CXF開發RESTFul服務REST
- maven+CXF+Spring+tomcat 開發webserviceMavenSpringTomcatWeb
- 翻譯-使用Spring呼叫SOAP Web ServiceSpringWeb
- Spring Web Service教程SpringWeb
- Spring整合CXF,釋出RSETful 風格WebServiceSpringWeb
- 翻譯-使用Spring WebService生成SOAP Web ServiceSpringWeb
- 使用Spring Boot開發Web專案Spring BootWeb
- 分散式系統系列(三)---Web Service實戰--CXF理論篇分散式Web
- Spring和cxf3的整合,以maven的方式SpringMaven
- 基於spring-boot&spring-data-jpa的web開發環境整合SpringbootWeb開發環境
- Spring Boot 的 Web 開發Spring BootWeb
- 什麼是web service?- SOAP Web Service & Restful Web ServiceWebREST
- 資料庫.NET中的Web service的開發資料庫Web
- Spring與Web環境整合SpringWeb
- 移動Web前端開發資源整合Web前端
- Spring Boot(二):Web 綜合開發Spring BootWeb
- Spring Boot (二):Web 綜合開發Spring BootWeb
- 如何用java技術快速開發web service專案JavaWeb
- SpringBoot整合Apache-CXF實踐Spring BootApache
- 如何使用ABSL程式碼呼叫Web serviceWeb
- 利用 Lotus Web Service Consumer 整合 WebSphere Process Server 業務流程WebServer
- [譯]使用 Rust 開發一個簡單的 Web 應用,第 3 部分 —— 整合RustWeb