使用CXF开发WebService服务器端接口
来源:互联网 发布:java参数公式 编辑:程序博客网 时间:2024/05/18 02:15
CXF作为java领域主流的WebService实现框架,Java程序员有必要掌握它。
CXF主页:http://cxf.apache.org/
简介:百度百科
1.首先建一个Maven的项目,项目结构:
pom.xml文件引入:
<dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-core</artifactId><version>3.1.5</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-frontend-jaxws</artifactId><version>3.1.5</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-rt-transports-http-jetty</artifactId><version>3.1.5</version></dependency></dependencies>
2.创建一个interface service
package com.milosun.webservice.service;import javax.jws.WebService;@WebServicepublic interface HelloWorldService {public String say(String name);}
3.创建一个 implements class
package com.milosun.webservice.service.impl;import javax.jws.WebService;import com.milosun.webservice.service.HelloWorldService;@WebServicepublic class HelloWorldServiceImpl implements HelloWorldService {public String say(String name) {return "Hello:"+name;}}
4.创建一个server class
package com.milosun.webservice.server;import javax.xml.ws.Endpoint;import com.milosun.webservice.service.HelloWorldService;import com.milosun.webservice.service.impl.HelloWorldServiceImpl;public class Server {public static void main(String[] args) {System.out.println("web service start!");HelloWorldService implementor = new HelloWorldServiceImpl();String address = "http://192.168.1.100/helloWorld";Endpoint.publish(address, implementor);System.out.println("web service end!");}}
或者:
package com.milosun.webservice.server;import org.apache.cxf.jaxws.JaxWsServerFactoryBean;import com.milosun.webservice.service.HelloWorldService;import com.milosun.webservice.service.impl.HelloWorldServiceImpl;public class Server {public static void main(String[] args) {System.out.println("web service start!");HelloWorldService implementor = new HelloWorldServiceImpl();String address = "http://192.168.1.100/helloWorld";//Endpoint.publish(address, implementor); //JDK 实现 JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean(); factoryBean.setAddress(address); // 设置暴露地址 factoryBean.setServiceClass(HelloWorldService.class); // 接口类 factoryBean.setServiceBean(implementor); // 设置实现类 factoryBean.create(); System.out.println("web service started!");}}
结果是一样的效果,只不过调用的方式不同。
5.测试结果:
console print:
web service start!十二月 20, 2017 1:04:01 下午 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass信息: Creating Service {http://impl.service.webservice.milosun.com/}HelloWorldServiceImplService from class com.milosun.webservice.service.HelloWorldService十二月 20, 2017 1:04:02 下午 org.apache.cxf.endpoint.ServerImpl initDestination信息: Setting the server's publish address to be http://192.168.1.100:80/helloWorldSLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.web service end!
browser 访问:http://192.168.1.103/helloWorld?wsdl
结论:这样一个简单的ws server 就创建完成了,下一章我们开始编写一个客户端来调用者个接口。
阅读全文
1 0
- 使用CXF开发WebService服务器端接口
- 使用CXF开发WebService服务器端接口
- CXF开发WebService服务器端接口
- 使用CXF开发WebService服务器端接口学习笔记一
- 【WebService】2.CXF概述和使用CXF开发WebService服务器端
- webservice+cxf接口开发
- WebService第二课 CXF功能概述_CXF发展历史和使用CXF开发WebService服务器端
- 使用cxf开发webservice
- 使用cxf 开发webservice
- 使用CXF开发WebService
- 使用cxf开发WebService
- 使用CXF开发WebService
- 使用cxf开发webservice
- CXF开发webService客户端调用服务器端测试
- 使用cxf技术开发webService接口
- 使用CXF 开发SOAP 的webService接口客户端
- webservice第三篇【接口开发webservice、CXF框架使用、IDEA下使用webservice、小例子】
- 【WebService开发】之使用CXF开发WebService
- 实现动态加载的图片页面中纵向居中显示
- nginx的内置缓存功能
- 2017-12-20
- hdoj 1197 specialized four-digit numbers(水)
- DroidBox环境搭建
- 使用CXF开发WebService服务器端接口
- 仿微信朋友圈图片预览自定义View
- 前端菜鸟用Vue+express+mysql自己撸了个简单博客
- 机器学习中的分类算法总结
- Nagios基本介绍
- Django框架学习笔记(19.自定义分页)
- Android dumpsys命令详细使用
- c++ mfc时间生成工具
- 新手数据结构练习——二叉树