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

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

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

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

    CXFspring集成

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

    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 注解表示是要發(fā)布的web 服務(wù)

    2. spring-cxf.xml配置發(fā)布的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:指明具體的實現(xiàn)類.

    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服務(wù)器,輸入: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. 下面就開始創(chuàng)建一個客戶端程序,訪問這個web service, 同樣新建java project ,并加入apache-cxf-2.0.7/lib所有包. 創(chuàng)建與具體webservice技術(shù)無關(guān)的業(yè)務(wù)接口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 閱讀(1007) 評論(0)  編輯  收藏 所屬分類: cxf

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产黄色一级毛片亚洲黄片大全 | 日本高清不卡aⅴ免费网站| 亚洲综合伊人久久综合| 免费看搞黄视频网站| 亚洲二区在线视频| 国产免费资源高清小视频在线观看| 亚洲国产成人久久精品软件| 亚洲精品色婷婷在线影院| 99久久综合精品免费| 亚洲大码熟女在线观看| 亚洲精品午夜无码电影网| 免费精品国产自产拍在线观看图片 | 中国黄色免费网站| 亚洲一区二区三区深夜天堂| 亚洲AV伊人久久青青草原| 三级毛片在线免费观看| 激情综合亚洲色婷婷五月| 亚洲一区日韩高清中文字幕亚洲| 久久国产免费观看精品3| 曰批全过程免费视频观看免费软件 | 伊人久久精品亚洲午夜| 国拍在线精品视频免费观看| 精品多毛少妇人妻AV免费久久| 亚洲国产精品成人综合色在线婷婷| 免费人成视频在线观看不卡| 在线看片免费人成视久网| 免费在线观看一区| 亚洲乱码无限2021芒果| 国产亚洲综合成人91精品| 国产在线19禁免费观看国产| 日本视频免费高清一本18| 无码毛片一区二区三区视频免费播放| 日韩免费一区二区三区在线 | 91亚洲国产成人精品下载| 男女啪啪免费体验区| 亚洲精品国产成人| 波多野结衣中文一区二区免费| 色欲国产麻豆一精品一AV一免费| 国产亚洲漂亮白嫩美女在线| 亚洲国产成人久久精品app| 亚洲AV综合色区无码一区爱AV|