瘋狂

          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());
            
           }

          完成。

          主站蜘蛛池模板: 元氏县| 莱州市| 临澧县| 北票市| 安义县| 禄丰县| 东乌珠穆沁旗| 濮阳县| 应城市| 喀喇| 邯郸市| 彭水| 江城| 抚远县| 乐东| 蒙自县| 阳春市| 泰安市| 绍兴县| 成安县| 通海县| 长汀县| 航空| 麻城市| 策勒县| 孟津县| 怀柔区| 内江市| 五大连池市| 普兰店市| 武威市| 农安县| 濮阳县| 区。| 公主岭市| 平江县| 建始县| 登封市| 南乐县| 扬中市| 林西县|