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

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

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

    posts - 15,  comments - 8,  trackbacks - 0
    原文出自:http://www.tkk7.com/xmatthew/archive/2008/11/02/238208.html    作者:xmatthew

    Spring2 針對(duì)遠(yuǎn)程訪問(wèn)服務(wù),提供的一個(gè)remote包。其的的是提供一套統(tǒng)一的遠(yuǎn)程服務(wù)發(fā)布功能。
    先來(lái)看一下Spring2支持那些遠(yuǎn)程服務(wù)功能:
        1. RMI服務(wù)
        2. Hessian或者Burlap通過(guò)HTTP遠(yuǎn)程調(diào)用服務(wù)
        3. HTTP調(diào)用器暴露服務(wù)

    下面用一個(gè)例子,來(lái)看一下Spring2 是怎樣對(duì)這些服務(wù)進(jìn)行統(tǒng)一的封裝和管理。

    先看一下服務(wù)器端的源代碼
    public interface IBookService {

        Book getById(String id);

    }

    public class Book {

        
    public String name;
        
    public String id;
        
    public String author;

    }
        
    public class BookService implements IBookService {

        
    public Book getById(String id) {
            
    return BookStore.getById(id);
        }

    }  

    客戶端源代碼
    public class BookQueryService {
      
    private IBookService bookService;
      
    public void setAccountService(IBookService bookService) {
        
    this.bookService = bookService;
      }
      
      
    public Book getBookById(String id) {
          
    return bookService.getById(id);
      }
    }

    //客戶端調(diào)用示例

    public static void main(String[] args) {

      ClassPathXmlApplicationContext context;
        context 
    = new  ClassPathXmlApplicationContext("applicationContext.xml");
        BookQueryService bookQueryService 
    = (BookQueryService) context.getBean("bookQueryService");
        Book book 
    = bookQueryService.getBookById("1");
    }

    使用Spring2 發(fā)布 RMI服務(wù)示例
    服務(wù)器端配置:
    <bean id="bookService" class="com.xmatthew.spring.remote.BookService">
    </bean>

    <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
        
    <!-- does not necessarily have to be the same name as the bean to be exported -->
        
    <property name="serviceName" value="bookService"/>
        
    <property name="service" ref="bookService"/>
        
    <property name="serviceInterface" value="com.xmatthew.spring.remote.IBookService"/>
        
    <property name="registryPort" value="1800"/>
    </bean>

    客戶端配置:

    <bean class="com.xmatthew.spring.remote.client.BookQueryService">
        
    <property name="bookService" ref="bookService"/>
    </bean>

    <bean id="bookService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        
    <property name="serviceUrl" value="rmi://localhost:1800/bookService"/>
        
    <property name="serviceInterface" value="com.xmatthew.spring.remote.IBookService"/>
    </bean>

    使用Spring2 發(fā)布 基于Http的Hessian服務(wù)示例
    注: Hessian提供一種基于HTTP的二進(jìn)制遠(yuǎn)程協(xié)議。它是由Caucho創(chuàng)建的,可以在 http://www.caucho.com 找到更多有關(guān)Hessian的信息。
     
    首為使用Hessian,需要為其配置Spring 的 DispatcherServlet
    把下面的配置加入到web.xml中
    <servlet>
        
    <servlet-name>remoting</servlet-name>
        
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        
    <servlet-name>remoting</servlet-name>
        
    <url-pattern>/remoting/*</url-pattern>
    </servlet-mapping>

    服務(wù)器端配置:
    <bean id="bookService" class="com.xmatthew.spring.remote.BookService">
    </bean>

    <bean name="/bookService" class="org.springframework.remoting.caucho.HessianServiceExporter">
      
    <property name="service" ref="bookService"/>
      
    <property name="serviceInterface" value="com.xmatthew.spring.remote.IBookService"/>
    </bean>

    客戶端配置:

    <bean class="com.xmatthew.spring.remote.client.BookQueryService">
        
    <property name="bookService" ref="bookService"/>
    </bean>

    <bean id="bookService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        
    <property name="serviceUrl" value="http://localhost:8080/bookService"/>
        
    <property name="serviceInterface" value="com.xmatthew.spring.remote.IBookService"/>
    </bean>

    使用Spring2 發(fā)布 基于Http的Burlap服務(wù)示例
     Burlap,它是一個(gè)基于XML的Hessian替代方案。它的配置方法和上述Hessian的一樣。只要把 Hessian 換成 Burlap 就行了。
     服務(wù)器端使用:
         org.springframework.remoting.caucho.BurlapServiceExporter 發(fā)布服務(wù)
     客戶端使用:
         org.springframework.remoting.caucho.BurlapProxyFactoryBean

    使用Spring2 發(fā)布 基于HTTP調(diào)用器暴露服務(wù)
    和使用自身序列化機(jī)制的輕量級(jí)協(xié)議Burlap和Hessian相反,Spring HTTP調(diào)用器使用標(biāo)準(zhǔn)Java序列化機(jī)制來(lái)通過(guò)HTTP暴露業(yè)務(wù).
    但其配置與Burlap和Hessian很相近

    服務(wù)器端配置:
    <bean id="bookService" class="com.xmatthew.spring.remote.BookService">
    </bean>

    <bean name="/bookService" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
      
    <property name="service" ref="bookService"/>
      
    <property name="serviceInterface" value="com.xmatthew.spring.remote.IBookService"/>
    </bean>

    客戶端配置:

    <bean class="com.xmatthew.spring.remote.client.BookQueryService">
        
    <property name="bookService" ref="bookService"/>
    </bean>

    <bean id="bookService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
        
    <property name="serviceUrl" value="http://localhost:8080/bookService"/>
        
    <property name="serviceInterface" value="com.xmatthew.spring.remote.IBookService"/>
    </bean>



    posted on 2008-11-04 12:05 lvq810 閱讀(234) 評(píng)論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 午夜网站免费版在线观看| 亚洲.国产.欧美一区二区三区| 曰韩无码AV片免费播放不卡| 国产亚洲福利一区二区免费看| 亚洲成a人无码亚洲成av无码| 免费可以在线看A∨网站| 亚洲免费闲人蜜桃| 亚洲成人在线免费观看| 亚洲婷婷综合色高清在线| 日本最新免费网站| 亚洲av无码一区二区三区天堂| 亚洲国产精品自在线一区二区| 免费91最新地址永久入口| 亚洲成人动漫在线| 韩国免费一级成人毛片| 亚洲丶国产丶欧美一区二区三区| 久久亚洲中文字幕精品有坂深雪| 好男人www免费高清视频在线| 无码一区二区三区免费| 亚洲中文字幕乱码一区| 亚洲毛片av日韩av无码| 免费a级毛片无码a∨免费软件| 亚洲成综合人影院在院播放| 久久久久亚洲av无码专区蜜芽| 色久悠悠婷婷综合在线亚洲| 18pao国产成视频永久免费| 久久久精品免费视频| 一本色道久久88—综合亚洲精品 | 国产成人精品日本亚洲网址| 暖暖日本免费在线视频| 免费无码又爽又刺激一高潮| 久久国产一片免费观看| 亚洲国产午夜电影在线入口| 亚洲精品美女在线观看播放| 国产L精品国产亚洲区久久| 18禁美女黄网站色大片免费观看| 美丽姑娘免费观看在线观看中文版 | 亚洲另类无码专区丝袜| 国产亚洲高清不卡在线观看| 在线精品一卡乱码免费| 成人网站免费大全日韩国产 |