BlogJava 聯(lián)系 聚合 管理  

          Blog Stats

          隨筆檔案(17)

          文章檔案(1)


          GaoWei


          1.新建接口
          package demo.spring;
          import javax.jws.WebService;
          @WebService
          public interface HelloWorld {
              String sayHi(String text);
          }
          // END SNIPPET: service

           

           

           


          2.接口實現(xiàn)
          package demo.spring;

          import javax.jws.WebService;

          @WebService(endpointInterface = "demo.spring.HelloWorld")
          public class HelloWorldImpl implements HelloWorld {

              public String sayHi(String text) {
                  return "Hello " + text;
              }

           

           

           

           


          package demo.spring.client;
          import org.springframework.context.support.ClassPathXmlApplicationContext;
          import demo.spring.HelloWorld;

          public final class Client {

              private Client() {
              }

              public static void main(String args[]) throws Exception {
                  // START SNIPPET: client
                  ClassPathXmlApplicationContext context
                      = new ClassPathXmlApplicationContext(new String[] {"demo/spring/client/client-beans.xml"});

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

                  String response = client.sayHi("Joe");
                  System.out.println("Response: " + response);
                  System.exit(0);
                  // END SNIPPET: client
              }
          }


          client-beans.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!-- START SNIPPET: beans -->
          <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="demo.spring.HelloWorld"
                factory-bean="clientFactory" factory-method="create"/>
             
           <bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
             <property name="serviceClass" value="demo.spring.HelloWorld"/>
             <property name="address" value="http://localhost:8080/example/jws/HelloWorld"/>
           </bean>
            
          </beans>
          <!-- END SNIPPET: beans -->

          applicationContext.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!-- START SNIPPET: beans -->
          <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="helloWorld"
             implementor="demo.spring.HelloWorldImpl"
             address="/HelloWorld" />
            
          </beans>
          <!-- END SNIPPET: beans -->

           


          <?xml version="1.0" encoding="UTF-8"?>
          <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
            <display-name>example</display-name>
           
            <listener>
            <listener-class>
             org.springframework.web.context.ContextLoaderListener
            </listener-class>
           </listener>

           <servlet>
            <servlet-name>CXFServlet</servlet-name>
            <display-name>CXF Servlet</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>/jws/*</url-pattern>
           </servlet-mapping>
            <welcome-file-list>
              <welcome-file>index.html</welcome-file>
              <welcome-file>index.htm</welcome-file>
              <welcome-file>index.jsp</welcome-file>
              <welcome-file>default.html</welcome-file>
              <welcome-file>default.htm</welcome-file>
              <welcome-file>default.jsp</welcome-file>
            </welcome-file-list>
          </web-app>

          posted on 2007-12-05 10:03 gggg874 閱讀(631) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 宁南县| 宜州市| 台北市| 阿坝县| 伊吾县| 武宁县| 苗栗县| 东辽县| 宁陕县| 连南| 通城县| 炉霍县| 罗江县| 基隆市| 吉隆县| 星座| 淳化县| 大荔县| 东源县| 桐乡市| 桦南县| 泾源县| 旬阳县| 巴东县| 孝义市| 改则县| 南乐县| 庄河市| 仁怀市| 东宁县| 大足县| 当涂县| 威信县| 平遥县| 揭阳市| 伊吾县| 台中县| 正蓝旗| 凤阳县| 山东省| 尤溪县|