注意:jar包还是*.jar哦!!!
?
先说发布的方法总结!
?
第一种:用一个j2se的main方法来发布
?
- public?class?Server?{??
- ????public?static?void?main(String[]?args)?{??
- ????????Endpoint.publish("http://127.0.0.1:8080/cxf",?new?HelloImpl());??
- ????}??
- }??
?
第二种用tomcat来发布
webX.xml:
<servlet>??
- ????<servlet-name>CXFServlet</servlet-name>??
- ????<servlet-class>t.T</servlet-class>??
- ????<init-param>??
- ????????<param-name>/hello</param-name>??
- ????????<param-value>t.HelloImpl</param-value>??
- ????</init-param>??
- ????<load-on-startup>1</load-on-startup>??
- </servlet>??
- <servlet-mapping>??
- ????<servlet-name>CXFServlet</servlet-name>??
- ????<url-pattern>/services/*</url-pattern>??
- </servlet-mapping>??
?
t.java:
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);??
- ??????????
- ????????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)?{??
- ????????????????}??
- ????????????}?catch?(ClassNotFoundException?e)?{??
- ????????????????e.printStackTrace();??
- ????????????}??
- ????????}??
- ????}??
- }??
?
第三种:还是用tomcat,但是采用spring的一些东东。
web.xml
<context-param>??
- ????<param-name>contextConfigLocation</param-name>??
- ????<param-value>/WEB-INF/beans.xml</param-value>??
- </context-param>??
- <listener>??
- ????<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>??
- </listener>??
- <servlet>??
- ????<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>??
- ????<load-on-startup>1</load-on-startup>??
- </servlet>??
- <servlet-mapping>??
- ????<url-pattern>/services/*</url-pattern>??
- </servlet-mapping>??
?
同目录还有一个beans.cml:
<?xml?version="1.0"?encoding="UTF-8"?>??
- <beans?xmlns="http://www.springframework.org/schema/beans"??
- ????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"??
- ????xmlns:jaxws="http://cxf.apache.org/jaxws"??
- ????xmlns:jaxrs="http://cxf.apache.org/jaxrs"??
- ????xsi:schemaLocation="http://www.springframework.org/schema/beans??
- ????http://www.springframework.org/schema/beans/spring-beans.xsd??
- ????http://cxf.apache.org/jaxws??
- ????http://cxf.apache.org/schemas/jaxws.xsd??
- ????http://cxf.apache.org/jaxrs??
- ????http://cxf.apache.org/schemas/jaxrs.xsd">??
- ??????
- ????<import?resource="classpath:META-INF/cxf/cxf.xml"?/>??
- ????<import?resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>??
- ????<import?resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"?/>??
- ????<import?resource="classpath:META-INF/cxf/cxf-servlet.xml"?/>??
- ??????
- ????<jaxws:endpoint?id="helloServiceWs"?address="/hello"?implementor="#helloService"?/>??
- ????<bean?id="helloService"?class="t.HelloImpl"?/>??
- </beans>??
?
再说一哈,客户端代码生成总结!!!这里提一下而已,多个思路。
?
1.手写:
public?class?Client?{??
- ????????JaxWsProxyFactoryBean?factory?=?new?JaxWsProxyFactoryBean();??
- ????????factory.setAddress("http://127.0.0.1/cxf_server/services/hello");??
- ????????factory.setServiceClass(HelloInter.class);??
- ????????HelloInter?helloInter?=?(HelloInter)?factory.create();??
- ????????helloInter.hello();??
- }??
?
2.用eclipse自动生成!
?
3.用XFire里面有的东西也可以生成。
?
4.用spring也可以生成。
?
5.用图形界面工具,比如soapui。(最简单)
?
6.用ant自动生成等等。
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|