<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

    CXFspring集成

    1 新建web project ,并加入apache-cxf-2.0.7/lib所有包,編寫要發布的web service 接口和實現.這一步,與前面一樣。

    import javax.jws.WebService;

    @WebService 

    public interface HelloWorld {  

         public String sayHello(String text);  

    }

    import javax.jws.WebService;  

    @WebService(endpointInterface="test.HelloWorld")  

    public class HelloWorldImpl implements HelloWorld {  

          public String sayHello(String text) {  

                      return "Hello" + text ;  

        }  

      } 

    @WebService 注解表示是要發布的web 服務

    2. spring-cxf.xml配置發布的web service 

    <?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" /> 

     

        <bean id="hello" class="test.HelloWorldImpl" /> 

        <jaxws:endpoint id="helloWorld" implementor="#hello" 

            address="/HelloWorld" /> 

      </beans>

    注意:<jaxws:endpoint id="helloWorld" implementor="#hello" 

            address="/HelloWorld" /> 

    id:指在spring配置的beanID.

    Implementor:指明具體的實現類.

    Address:指明這個web service的相對地址,

    3.  配置web.xml文件:

    <?xml version="1.0" encoding="UTF-8"?> 

    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   

        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

        <context-param> 

            <param-name>contextConfigLocation</param-name>  

            <param-value>classpath:spring-cxf.xml</param-value> 

        </context-param> 

     

        <listener> 

            <listener-class> 

             org.springframework.web.context.ContextLoaderListener 

            </listener-class> 

        </listener> 

           

        <servlet> 

            <servlet-name>CXFServlet</servlet-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>/*</url-pattern> 

        </servlet-mapping> 

    </web-app> 

    4部署到tomcat服務器,輸入:http://localhost:8080/<web-app-name>/ HelloWorld?wsdl,將顯示這個web servicewsdl.

    注意:如果web.xml配置<servlet-name>CXFServlet</servlet-name> 

            <url-pattern>/ws/*</url-pattern> 

    則訪問地址為:http://localhost:8080/<web-app-name>/ws/ HelloWorld?wsdl

    5. 下面就開始創建一個客戶端程序,訪問這個web service, 同樣新建java project ,并加入apache-cxf-2.0.7/lib所有包. 創建與具體webservice技術無關的業務接口HelloWorld.java

    public interface HelloWorld {  

         public String sayHello(String text);  

    }

    6.配置spring-client.xml

    <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-2.0.xsd

    http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">

     

        <bean id="client" class="test.HelloWorld"

          factory-bean="clientFactory" factory-method="create"/>

       

        <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">

          <property name="serviceClass" value="test.HelloWorld"/>

          <property name="address" value="http://localhost:9000/helloWorld"/>

    <!-- 這個地方的地址一定要注意,正確的-->

        </bean>

         

    </beans>

    7.測試:

    import org.springframework.context.ApplicationContext;

    import org.springframework.context.support.ClassPathXmlApplicationContext;

     

    import test.HelloWorld;

     

    public class Test {  

         

        public static void main(String[] args) {  

     

            ApplicationContext ctx = new ClassPathXmlApplicationContext(  

                    "spring-client.xml");  

            HelloWorld client = (HelloWorld) ctx.getBean("client");  

            String result = client.sayHello("你好!");  

            System.out.println(result);  

        }  

    } 

    8.參考資料

    http://java.dzone.com/articles/web-services-with-mule-cxf-and

    http://www.ibm.com/developerworks/webservices/library/ws-pojo-springcxf/index.html?ca=drs-http://wheelersoftware.com/articles/spring-cxf-web-services-4.html

     



    http://blog.csdn.net/pengchua/article/details/2740572
    posted on 2012-08-21 14:20 abin 閱讀(1004) 評論(0)  編輯  收藏 所屬分類: cxf

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 成人毛片18女人毛片免费96| 7x7x7x免费在线观看| 国产jizzjizz免费看jizz| 亚洲伊人色一综合网| 国产a视频精品免费观看| 亚洲国产美女精品久久久久| 久久精品无码专区免费青青| 亚洲首页在线观看| 51视频精品全部免费最新| 亚洲国产美女精品久久| 国产免费的野战视频| 一区二区亚洲精品精华液 | 久久免费精品一区二区| 国产AV无码专区亚洲AV漫画| 99在线免费观看| 78成人精品电影在线播放日韩精品电影一区亚洲 | 国产亚洲综合网曝门系列| 国产一级淫片a免费播放口| 99ri精品国产亚洲| 免费看韩国黄a片在线观看| 亚洲aⅴ无码专区在线观看| 亚洲精品久久久www| 免费成人在线电影| 亚洲av无码久久忘忧草| 可以免费观看的一级毛片| 日本一区午夜艳熟免费| 亚洲欧洲精品一区二区三区| 一二三四在线播放免费观看中文版视频| 亚洲精品国产suv一区88| 久久亚洲国产成人影院网站 | 亚洲色精品vr一区二区三区| 久久久久高潮毛片免费全部播放| 成人区精品一区二区不卡亚洲| 少妇亚洲免费精品| 久久精品视频免费播放| 亚洲中文无码亚洲人成影院| 国产国拍亚洲精品福利| 亚洲啪啪免费视频| 精品在线观看免费| 亚洲综合日韩中文字幕v在线 | 日韩内射激情视频在线播放免费|