基于Apache CXF和Java(spring+maven)的webservice服务端实现
来源:互联网 发布:冯文乐网络春晚 编辑:程序博客网 时间:2024/06/01 08:45
webservice是一种跨编程语言和操作系统的远程调用技术。通俗来讲即:将一些内部系统的业务方法发布成webservice服务,供其他使用者调用。具体相关原理可自行查询。本文是介绍在spring+maven框架的基础上,基于Java编程语言和Apache CXF框架来实现服务端业务方法发布成webservice的过程。
1.构建基本的maven项目mavenTest,并搭建基本的spring框架
本文搭建了springmvc+spring+mybatis架构,即添加相关依赖jar和配置文件,可实现对MySQL数据库的操作。
2.在pom.xml中添加Apache cxf框架的依赖jar包
<!-- cxf config --><dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.8</version></dependency><dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.8</version></dependency>3.在web.xml中配置cxf servlet<servlet> <description>CXF Endpoint</description> <display-name>cxf</display-name> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>2</load-on-startup></servlet><servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/services/*</url-pattern><!-- 开放服务列表路径 --></servlet-mapping>4.在spring容器配置文件中添加
<import resource="spring-cxf.xml" /><!-- 导入cxf配置文件 -->
spring-cxf.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://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <import resource="classpath:META-INF/cxf/cxf.xml" /> <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <!-- Cxf WebService 服务端示例 --> <jaxws:endpoint id="demoWebservice" implementor="mavenTest.service.DemoWebserviceImpl" address="/demo"/></beans>5.经过以上的配置,接下来准备需要发布成webservice服务的业务方法,即上面配置文件中的id="demoWebservice"
package mavenTest.service;import javax.jws.WebService;@WebServicepublic interface DemoWebservice {public String query();public String queryById(String id);}package mavenTest.service;import java.util.List;import javax.jws.WebService;import org.springframework.beans.factory.annotation.Autowired;import com.google.gson.Gson;import mavenTest.dao.StudentsMapper;@WebService(endpointInterface = "mavenTest.service.DemoWebservice")public class DemoWebserviceImpl implements DemoWebservice{@Autowiredprivate StudentsMapper dao;@Overridepublic String query() {// TODO Auto-generated method stubList list=dao.selectAll();return new Gson().toJson(list);}@Overridepublic String queryById(String id) {// TODO Auto-generated method stubreturn new Gson().toJson(dao.selectByPrimaryKey(id));}}6.将mavenTest部署到Tomcat,在浏览器中输入http://localhost:8080/services/,如下图所示
7.上图为webservice列表,点击WSDL链接,即可查看文件
阅读全文
0 0
- 基于Apache CXF和Java(spring+maven)的webservice服务端实现
- CXF和Spring整合实现WebService服务端、客户端
- spring + cxf 的webservice服务端和客户端功能
- cxf依赖spring 方式实现webservice服务端
- Web Service (012---webservice使用CXF写基于Spring的WebService[服务端+客户端])
- cxf实现webservice服务端
- 基于Spring+CXF实现用户文件上传的WebService
- 基于spring+cxf实现用户文件传输的webservice
- 基于Spring和CXF的webservice开发环境搭建
- 基于Spring和CXF的webservice开发环境搭建
- 基于apache cxf的webservice小例子
- spring整合cxf webService(服务端)
- cxf+spring创建webservice服务端
- JAVA 用 Apache CXF 调用 .NET 服务端 WebService
- JAVA 用 Apache CXF 调用 .NET 服务端 WebService
- webservice之cxf实现[web项目中基于maven与spring整合]
- Apache CXF实现WebService
- Spring实现CXF服务端
- 中国日期格式
- python 多态性
- 用Div+CSS完成一个等腰梯形
- 01、UIPickerView-案例1
- 禅道 项目管理软件
- 基于Apache CXF和Java(spring+maven)的webservice服务端实现
- react-redux异步加载时使用的中间件
- wdatePicker日历控件
- 搜索框点击文字消失、带背景
- How can I find out which process and user is modifying a file?
- js内存泄漏详解
- Ubuntu14.04 +caffe+pycaffe安装
- Android CoordinatorLayout布局的使用方式和属性
- 软件工程(C编码实践篇)学习总结