首页 > 其他 > 详细

maven版cxf集合jetty开发服务端(一)

时间:2017-12-21 21:34:28      阅读:292      评论:0      收藏:0      [点我收藏+]

一、首先新建一个maven项目

二、pom.xml引入依赖 

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-api</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-bindings-soap</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-ws-security</artifactId>
    <version>2.5.0</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http-jetty</artifactId>
    <version>2.5.0</version>
</dependency>

三、开发接口类

package com.xie.ws;

import javax.jws.WebService;

@WebService
public interface HelloWorld {

    String sayHi(String username); 
}

四、开发实现类

import javax.jws.WebService;
import com.xie.ws.HelloWorld;


@WebService(endpointInterface="com.xie.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld {

    public String sayHi(String username) {
        System.out.println("Hello,"+username);
        return "Hello,"+username;
    }

}

五、创建服务

  1、java自带jetty启动  

import javax.xml.ws.Endpoint;
import com.xie.ws.impl.HelloWorldImpl;

public class WebServiceTest {

    public static void main(String[] args) {
        
        HelloWorldImpl hw = new HelloWorldImpl();
        String address = "http://localhost:8080/CxfWSServer";
        Endpoint.publish(address, hw);
        System.out.println("WebService暴露成功。。。");
        
    }
    
}

  2、浏览器访问:http://localhost:8080/CxfWSServer?wsdl  如图所示:

技术分享图片

 

maven版cxf集合jetty开发服务端(一)

原文:http://www.cnblogs.com/xiehongwei/p/8082337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!