cxf 发布多个接口的方法
1、使用cxf 中的 JaxWsServerFactoryBean类发布webservice
package server;import org.apache.cxf.jaxws.JaxWsServerFactoryBean;import hb.HelloWorldService;import hb.IHelloWorldService;import hb.ISessionSendMsg;import hb.SessionSendMsg;public class Server1 {public static void main(String[] args) {HelloWorldService helloworldimp = new HelloWorldService();JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean();factoryBean.setAddress("http://localhost:8080/WSCXF/helloService");factoryBean.setServiceClass(IHelloWorldService.class);//接口类factoryBean.setServiceBean(helloworldimp);factoryBean.create();JaxWsServerFactoryBean factoryBean1 = new JaxWsServerFactoryBean();SessionSendMsg sessionSendMsg = new SessionSendMsg();factoryBean1.setAddress("http://localhost:8080/WSCXF/sessionService");factoryBean1.setServiceClass(ISessionSendMsg.class);//接口类factoryBean1.setServiceBean(sessionSendMsg);factoryBean1.create();}}
?
?备注:实际上是创建了多个JaxWsServerFactoryBean对象来实现发布多个接口
?
2、使用java原生代码发布webservice
package server;import hb.HelloWorldService;import hb.SessionSendMsg;import javax.xml.ws.Endpoint;public class DeployHelloWorldService {public static void main(String[] args) {System.out.println("Server start ……");HelloWorldService service = new HelloWorldService();String address = "http://localhost:9000/helloWorld";Endpoint.publish(address, service);SessionSendMsg sessionSendMsg = new SessionSendMsg();String address1 = "http://localhost:9000/session";Endpoint.publish(address1, sessionSendMsg);}}
?
备注:实际上是Endpoint发布多次实现发布多个接口。