关闭

cxf 发布多个接口的方法

566人阅读 评论(0) 收藏 举报
分类:

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发布多次实现发布多个接口。

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:322773次
    • 积分:8882
    • 等级:
    • 排名:第2253名
    • 原创:1096篇
    • 转载:14篇
    • 译文:0篇
    • 评论:5条
    最新评论