CXF 不依赖spring的实现
cxf 也可以不依赖spring实现webservice
package com.servlet;
import javax.servlet.ServletConfig;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import com.Hello;
import com.HelloImpl;
public class WebServelet extends CXFNonSpringServlet { //主要是这一个继承CXFNonSpringServlet
@Override
protected void loadBus(ServletConfig sc) {
super.loadBus(sc);
Bus b=getBus();
BusFactory.setDefaultBus(b);
HelloImpl hi=new HelloImpl();//实现类
ServerFactoryBean sfb=new ServerFactoryBean(); //server工厂
sfb.setServiceClass(Hello.class);// 接口类
sfb.setAddress("/hi"); //服务请求路径
sfb.setServiceBean(hi);
sfb.create();
}
}
web.xml 配置
cxfServlet
com.servlet.WebServelet
1
cxfServlet
/ws/*
启动服务的时候就开启webservice接口
public static void main(String[] args) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(Hello.class);
factory.setAddress("http://localhost:8080/Temp1/ws/hi?wsdl");
Hello client = (Hello)factory.create();
System.out.println(client.say("foo"));
}
关键字:cxf
版权声明
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!