webservices——发布CXF的方法总结!!!

webservices——发布CXF的方法总结!!!
注意:jar包还是*.jar哦!!!

先说发布的方法总结!

第一种:用一个j2se的main方法来发布

[java] view plain copy
public class Server {
public static void main(String[] args) {
Endpoint.publish(“http://127.0.0.1:8080/cxf“, new HelloImpl());
}
}

第二种用tomcat来发布
webX.xml:
[xhtml] view plain copy

CXFServlet
t.T

/hello
t.HelloImpl

1


CXFServlet
/services/*

t.java:
[java] view plain copy
package t;

import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;

public class T extends CXFNonSpringServlet {

private static final long serialVersionUID = -4143021604478775522L;  

public void loadBus(ServletConfig servletConfig) throws ServletException {  
    super.loadBus(servletConfig);  
    Bus bus = this.getBus();  
    BusFactory.setDefaultBus(bus);  
    // 获取在web.xml中配置的要发布的所有的Web服务实现类并发布Web服务  
    Enumeration<String> enumeration = this.getInitParameterNames();  
    while (enumeration.hasMoreElements()) {  
        String key = enumeration.nextElement();  
        String value = this.getInitParameter(key);  
        try {  
            Class clazz = Class.forName(value);  
            try {  
                Endpoint.publish(key, clazz.newInstance());  
            } catch (InstantiationException e) {  
                e.printStackTrace();  
            } catch (IllegalAccessException e) {  
                e.printStackTrace();  
            }  
        } catch (ClassNotFoundException e) {  
            e.printStackTrace();  
        }  
    }  
}  

}

第三种:还是用tomcat,但是采用spring的一些东东。
web.xml
[xhtml] view plain copy

contextConfigLocation
/WEB-INF/beans.xml


org.springframework.web.context.ContextLoaderListener


CXFServlet
org.apache.cxf.transport.servlet.CXFServlet
1


CXFServlet
/services/*

同目录还有一个beans.cml:
[xhtml] view plain copy

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值