java webservice CXF 学习

首先还是下包 目前最新的CXF的下载地址http://cxf.apache.org/download.html,解压apache-cxf-3.0.2.zip

取该目录下的lib中的所有jar包放入项目中即可,samples目录下游很多实例可以用在参考

列举一个HellWorld

1.建立服务节点接口

package com.cxf.helloworld;

import javax.jws.WebParam;
import javax.jws.WebService;

/**
 * 首先服务点接口
 */
@WebService
public interface HelloWorld {
     String sayHi(@WebParam(name="text")String text);
}
2.编写服务实现

package com.cxf.helloworld;

import javax.jws.WebService;

/**
 * 编写服务实现
 */
@WebService(endpointInterface="com.cxf.helloworld.HelloWorld",serviceName="helloWorld")
public class HelloWorldImpl implements HelloWorld {

	public String sayHi(String text) {
		return "Hello"+text;
	}
}
3.编写 WebServiceApp类来暴露 web服务

package com.cxf.helloworld;

import javax.xml.ws.Endpoint;

public class WebServiceApp {

	/**
	 * 编写 WebServiceApp类来暴露 web服务
	 */
	public static void main(String[] args) {
		System.out.println("Starting Server");
        HelloWorldImpl implementor = new HelloWorldImpl();
        //http://localhost:9000/HelloWorld?wsdl
        String address = "http://localhost:9000/HelloWorld";
        Endpoint.publish(address, implementor);
        System.out.println("Started Server");
	}
}
运行WebServiceApp  打印 Started Server说明webService服务已经启动   访问 http://localhost:9000/HelloWorld?wsdl

看是否生成了我们所需要的wsdl文件


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值