<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>3.1.1</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
不建议使用,建议使用它的子类JaxWsServerFactory
使用这个服务类上不需要加@webservice注解
服务类没有服务方法,不报错
缺点是生成的wsdl文档命名不规范
package com.stduy.server;
public class PersonService {
public String sayHello(String userName){
return "hello "+userName;
}
}
public class Publisher {
public static void main(String[] args) {
//创建cxf服务发布对象
ServerFactoryBean sfb = new ServerFactoryBean();
//设置服务的类
sfb.setServiceClass(PersonService.class);
//设置服务地址
sfb.setAddress("http://localhost:5555/hello");
//设置服务类的对象
sfb.setServiceBean(new PersonService());
//发布
sfb.create();
}
}
发布后在浏览器方法http://localhost:5555/hello?wsdl可以得到wsdl
建议使用子类,不建议使用父类
服务类必须加@WebService注解,不然发布的时候,就会按照空服务进行发布
@WebService
public class PersonService {
public String sayHello(String userName){
return "hello "+userName;
}
}
public class Publisher {
public static void main(String[] args) {
//创建cxf服务发布对象
JaxWsServerFactoryBean sfb = new JaxWsServerFactoryBean();
//设置服务的类
sfb.setServiceClass(PersonService.class);
//设置服务地址
sfb.setAddress("http://localhost:5555/hello");
//设置服务类的对象
sfb.setServiceBean(new PersonService());
//发布
sfb.create();
}
}
如果发布带有接口的webservice需要在接口上加@webservice注解