BlogJava 聯系 聚合 管理  

          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.接口實現
          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)  編輯  收藏

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


          網站導航:
           
          主站蜘蛛池模板: 九江市| 迁西县| 普定县| 黄山市| 图木舒克市| 商都县| 那曲县| 彰化市| 新安县| 渝中区| 延庆县| 神农架林区| 灌云县| 霍林郭勒市| 平顶山市| 金沙县| 涪陵区| 潜江市| 新乡县| 洮南市| 嫩江县| 清苑县| 岳普湖县| 黄平县| 朔州市| 会东县| 永春县| 台中县| 孝昌县| 时尚| 德阳市| 慈溪市| 蓬溪县| 昌吉市| 密山市| 台前县| 大冶市| 越西县| 广河县| 巩留县| 墨玉县|