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"); } }