java webservice 服务器_WebService -- Java 实现之 CXF (WebService 服务器端接口)

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

6fe6818d7b526f03479b8a649eaed010.png

2. 引入依赖的Jar包

org.apache.cxf

cxf-core

3.1.5

org.apache.cxf

cxf-rt-frontend-jaxws

3.1.5

org.apache.cxf

cxf-rt-transports-http-jetty

3.1.5

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. 访问服务

345a08de2720ee794b6274dcc5130bb5.png

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值