【从本人QQ空间迁移】cxf开发webservice

eclipse 6
 tomcat 6
 apche-cxf 2.X (目前最高版本为3.0.3) 

 1、接口
       和普通接口没什么区别
       接口上需要加
@WebService  
       参数前需要加上 @WebParam(name="xxx")
 2、接口实现
       @WebService(endpointInterface="包路径+类名",serviceName="服务名称")
 3、接口暴露
       String address="http://localhost:8080/xxxx地址";
       Endpoint.publish(address, 实现类对象);
 4、测试发布
       http://localhost:8080/xx项目名/xxxx地址?wsdl
 5、集成到spring
       web.xml
       -------
       <?xml version="1.0" encoding="UTF-8"?>

           <web-app>
                <welcome-file-list>
                         <welcome-file>index.jsp</welcome-file>
                </welcome-file-list>

                <context-param>
                          <param-name>contextConfigLocation</param-name>
                          <param-value>WEB-INF/classes/applicationContext.xml</param-value>
                 </context-param>
 
              <listener>
                      <listener-class>
                              org.springframework.web.context.ContextLoaderListener
                      </listener-class>
              </listener>

              <servlet>
                     <servlet-name>CXFServlet</servlet-name>
                     <display-name>CXFServlet</display-name>
                     <servlet-class>
                            org.apache.cxf.transport.servlet.CXFServlet
                     </servlet-class>
                     <load-on-startup>1</load-on-startup>
               </servlet>

               <servlet-mapping>
                      <servlet-name>CXFServlet</servlet-name>
                      <url-pattern>/webservice/*</url-pattern>
               </servlet-mapping>
         </web-app>

         --------------------------------------------------------------------------------------------------------------

         applicationContext.xml

         ----------------------------

         <?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"
                 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">
 
                <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-servlet.xml"/>
 
                 <jaxws:endpoint  id="地址" implementor="实现类"  address="/xxxx地址" />
   
                <bean id="client" class="接口类"  factory-bean="clientFactory" factory-method="create"/>
    
                 <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
                            <property name="serviceClass" value="接口类"/>
                            <property name="address" 
value="http://localhost:8080/s/webservice/xxxx地址"/>

                  </bean>
                </beans>

   6、生成客户端

               配置好环境变量后,在cmd中执行

               wsdl2java.bat  -p  接口类 -client -encoding utf-8 -noAddressBinding http://127.0.0.1:8080/项目名/服务名?wsdl

猜你喜欢

转载自blog.csdn.net/wzh474420999/article/details/79634433
今日推荐