1. 使用Maven创建一个quickstart项目

2. 引入依赖的Jar包

<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>

3. 编写Service 接口 + 实现类

package com.example.tuo.webservice;

import javax.jws.WebService;

@WebService
public interface HelloWorld {

  public String sayHello(String sb);

}

package com.example.tuo.webservice.impl;

import javax.jws.WebService;

import com.example.tuo.webservice.HelloWorld;

@WebService
public class HelloWorldImpl implements HelloWorld{ public String sayHello(String sb) {
// TODO Auto-generated method stub
return "Hello world," +sb;
} }

4. 启动服务

package com.example.tuo.server;

import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

import com.example.tuo.webservice.HelloWorld;
import com.example.tuo.webservice.impl.HelloWorldImpl; public class Server { public static void main(String[] args){ System.out.println("web service starting..."); JaxWsServerFactoryBean wsSvrFactoryBean = new JaxWsServerFactoryBean();
String address = "http://127.0.0.1/helloWorld";
wsSvrFactoryBean.setAddress(address);
wsSvrFactoryBean.setServiceClass(HelloWorld.class);
HelloWorld implementor = new HelloWorldImpl();
wsSvrFactoryBean.setServiceBean(implementor);
wsSvrFactoryBean.create(); System.out.println("web service started...");
}
}

5. 访问服务

至此,我们的第一个基于CXF的webservice已经编写完成并发布出来了。

WebService -- Java 实现之 CXF (WebService 服务器端接口)的更多相关文章

  1. WebService -- Java 实现之 CXF ( 使用:Spring+CXF+Tomcat发布webService)

    1. 新建一个Maven项目,选择webapp模板,命名为WS_Spring_CXF_Tomcat 2. 在POM.xml中添加Spring和CXF的依赖 <!-- 添加 Spring depe ...

  2. JEECG(二) JEECG框架下调用webservice java springmvc maven 调用 webservice

    JEECG系列教程二 如何在JEECG框架下使用webservice 本文所使用的webservice是c#开发的 其实无论是什么语言开发的webservice用法都一样 java springmvc ...

  3. WebService -- Java 实现之 CXF (初体验)

    1. 认识WebService 简而言之,她就是:一种跨编程语言以及操作系统的远程调用技术. 大家都可以根据定义好的规范和接口进行开发,尽管各自的使用的开发语言和操作系统有所不同,但是由于都遵循统一的 ...

  4. ajax跨域访问 java controller 和 cxf(webservice) 配置方式(CORS)

    1. controller跨域访问,配置方式 重点在这里: <mvc:cors> <mvc:mapping path="/*" allowed-origins=& ...

  5. WebService -- Java 实现之 CXF ( 添加系统预定义的拦截器)

    1. 概述 CXF允许我们在webservice的in/out位置添加拦截器.拦截器有两大分类,一类是系统预定义的:另一类是自定义拦截器. 2. 在server端添加拦截器. JaxWsServerF ...

  6. WebService -- Java 实现之 CXF ( 使用CXF工具生成client 程序)

    1. 下载CXF 工具解压到磁盘 2.添加工具bin目录到PATH环境变量 3.创建一个CXF client新项目 4. run -> cmd 到指定目录,并运行工具目录下的批处理 “wadl2 ...

  7. WebService -- Java 实现之 CXF ( 使用Spring添加拦截器)

    最重要的就是在ApplicationContext.xml下面添加配置 <!-- service provider --> <jaxws:endpoint implementor=& ...

  8. (二)使用CXF开发WebService服务器端接口

    CXF作为java领域主流的WebService实现框架,Java程序员有必要掌握它. CXF主页:http://cxf.apache.org/ 简介:百度百科 今天的话,主要是用CXF来开发下Web ...

  9. java调用CXF WebService接口的两种方式

    通过http://localhost:7002/card/services/HelloWorld?wsdl访问到xml如下,说明接口写对了. 2.静态调用 // 创建WebService客户端代理工厂 ...

随机推荐

  1. MVC FormCollection collection

    1.通过name获取值 collection.GetValues() 返回一个数组,适用于多选等,如果是单值可以[0] 2.直接转化为实体 将Action动作中传递的FormCollection转变成 ...

  2. 深入理解Java:内部类

    什么是内部类? 内部类是指在一个外部类的内部再定义一个类.内部类作为外部类的一个成员,并且依附于外部类而存在的.内部类可为静态,可用protected和private修饰(而外部类只能使用public ...

  3. Good Bye 2016 //智商再次下线,边界爆炸.....

    A B很水就略了.. C.又是一次wannafly一样的判断区间的.....  边界设为2000000  正好GG...... fst的时候立马想到上次也是这么wa过的...... 所以下次遇到这种题 ...

  4. 【51Nod 1616】【算法马拉松 19B】最小集合

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1616 这道题主要是查询一个数是不是原有集合的一个子集的所有数的gcd. ...

  5. Python学习 过程中零散知识点的总结

    自学资料比较零碎,本文是对在Python学习过程中积累的零零散散的知识点的总结 ============================================================ ...

  6. Linux 查找文件并删除文件内容

    find * ./ |while read file; do echo ''>$file; done

  7. ReactNative 适合初学的第一个教程demo,找租房

    1.下载工程 我看来看去,最让人容易入门的是这个demo: https://github.com/rayshen/PropertyFinder 是英国某开发者做的搜租房的小demo,包含的知识有:图片 ...

  8. MongoDB高可用复制集分片集群搭建

    1     逻辑架构 1.1     逻辑架构图 1.2     组件说明 一.mongos(query routers):查询路由,负责client的连接,并把任务分给shards,然后收集结果.一 ...

  9. 【Beta】第六次任务发布

    PM #103 #85 日常管理&dev版宣传&新增报告管理后台. 后端 #101 完成收藏功能 完成管理员权限表的生成和接入(按位压缩权限表) 验收条件:收藏功能能够正常使用.能够区 ...

  10. linux 安装后

    docker https://cr.console.aliyun.com/#/accelerator pecl install xdebug xdebug.remote_enable = on php ...