1. 程式人生 > >maven版cxf集合jetty開發服務端(一)

maven版cxf集合jetty開發服務端(一)

tin 啟動 pid blog maven new inter sports host

一、首先新建一個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開發服務端(一)