一、新建一个Maven项目,并导入相应的依赖
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>2.2.3</version>
</dependency>
二、新建一个WebService
package com.TheService.service;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService//标注为WebService
public class Hello {
@WebMethod
@WebResult(name="helloresult")
public String hello() {
return "Hello";
}
}
三、新建一个main方法,发布WebService
package com.TheService;
import javax.xml.ws.Endpoint;
import com.TheService.service.Hello;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println("开始发布");
Endpoint.publish("http://localhost:8088/hello", new Hello());//再一次发布中,一个端口可以发布多个WebService
Endpoint.publish("http://localhost:8088/hello", new Hello());//再一次发布中,一个端口可以发布多个WebService
System.out.println("发布成功");
}
}