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

来源:互联网 发布:乐高编程软件 编辑:程序博客网 时间:2024/06/06 17:49

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

原创粉丝点击