瘋狂

          STANDING ON THE SHOULDERS OF GIANTS
          posts - 481, comments - 486, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          spring httpinvoker 例子

          Posted on 2010-01-27 16:33 瘋狂 閱讀(2512) 評論(0)  編輯  收藏 所屬分類: spring

          1,創建接口:

          public interface HttpInvokerTestI {

           public TestPo getTestPo(String desp);
          }


          實現:

          public class HttpInvokertestImpl implements HttpInvokerTestI {

           @Override
           public TestPo getTestPo(String desp) {
            // TODO Auto-generated method stub
            return new TestPo(desp);
           }

          }


          配置:在web info下添加remote-servlet.xml

          內容:

           <bean name="httpinvokertest" class="ztest.httpinvoke.HttpInvokertestImpl"/>
               <bean name="/hit" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
                  <property name="service" ref="httpinvokertest"/>
                  <property name="serviceInterface" value="ztest.httpinvoke.HttpInvokerTestI"/>
               </bean>

          添加spring.jar spring-webmvc.jar(配置dispacherServlet用)
          web.xml 添加對context和servlet的支持:

          <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
             classpath:applicationContext-*.xml
            </param-value>
           </context-param>

           <listener>
            <listener-class>
             org.springframework.web.context.ContextLoaderListener
            </listener-class>
           </listener>



          <servlet>  
                  <servlet-name>remote</servlet-name>  
                  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
                       <load-on-startup>1</load-on-startup>  
              </servlet>  
              <servlet-mapping>  
                 <servlet-name>remote</servlet-name>  
                 <url-pattern>/remoting/*</url-pattern>   
              </servlet-mapping> 

          客戶端配置:

          <bean id="remoteService"
              class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
                 <property name="serviceUrl"
                     value="http://localhost:8080/ssh/remoting/hit" />
                 <property name="serviceInterface" value="com.s.httpinvoker.HttpInvokerTestI"/>

              </bean>

          測試類:
          public static void main(String[] args) {
            ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext-bean.xml");
            HttpInvokerTestI httpInvokerTestI = (HttpInvokerTestI) context.getBean("remoteService");
            System.out.println(httpInvokerTestI.getTestPo("dddd").getDesp());
            
           }

          完成。

          主站蜘蛛池模板: 巴塘县| 双牌县| 兴宁市| 托克逊县| 梅河口市| 清涧县| 资溪县| 涟水县| 南部县| 牙克石市| 武清区| 林口县| 抚顺县| 光泽县| 太康县| 镇康县| 塔城市| 安顺市| 平南县| 雅安市| 汝城县| 商水县| 鱼台县| 奉新县| 彰武县| 江达县| 金溪县| 临潭县| 和政县| 永城市| 宜丰县| 西乡县| 淮安市| 云南省| 漯河市| 波密县| 大荔县| 清徐县| 高安市| 南召县| 夏邑县|