学习webservice之cxf(1):使用cxf实现webservice(使用jdk1.8)

maven代码:

  <dependencies>
      <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>3.2.5</version>
    </dependency>
      <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-core</artifactId>
        <version>3.2.5</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>3.2.5</version>
    </dependency>
  </dependencies>

 Server代码:

package com.rg2.webservice.impl;

import javax.xml.ws.Endpoint;

import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

import com.rg2.webservice.HelloWorld;

public class Server {

    public static void main(String[] args) {
        System.out.println("web service start");
        HelloWorld implementor = new HelloWorldImpl();
        String address = "http://localhost/helloWorld";
//        Endpoint.publish(address, implementor);//jdk实现暴露webservice接口
        JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();
        factoryBean.setAddress(address);//设置暴露地址
        factoryBean.setServiceClass(HelloWorld.class);//接口类
        factoryBean.setServiceBean(implementor);//设置实现类
        factoryBean.create();//创建webservice接口
        System.out.println("web service started");
    }

}
原文地址:https://www.cnblogs.com/zhengyuanyuan/p/9265628.html