码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-12-21 21:51:14      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:pid   user   post   public   ring   apache   artifact   span   成功   

一、首先新建一个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开发服务端(一)

标签:pid   user   post   public   ring   apache   artifact   span   成功   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!