<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 針對遠程訪問服務,提供的一個remote包。其的的是提供一套統一的遠程服務發布功能。
    先來看一下Spring2支持那些遠程服務功能:
        1. RMI服務
        2. Hessian或者Burlap通過HTTP遠程調用服務
        3. HTTP調用器暴露服務

    下面用一個例子,來看一下Spring2 是怎樣對這些服務進行統一的封裝和管理。

    先看一下服務器端的源代碼
    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);
      }
    }

    //客戶端調用示例

    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 發布 RMI服務示例
    服務器端配置:
    <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 發布 基于Http的Hessian服務示例
    注: Hessian提供一種基于HTTP的二進制遠程協議。它是由Caucho創建的,可以在 http://www.caucho.com 找到更多有關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>

    服務器端配置:
    <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 發布 基于Http的Burlap服務示例
     Burlap,它是一個基于XML的Hessian替代方案。它的配置方法和上述Hessian的一樣。只要把 Hessian 換成 Burlap 就行了。
     服務器端使用:
         org.springframework.remoting.caucho.BurlapServiceExporter 發布服務
     客戶端使用:
         org.springframework.remoting.caucho.BurlapProxyFactoryBean

    使用Spring2 發布 基于HTTP調用器暴露服務
    和使用自身序列化機制的輕量級協議Burlap和Hessian相反,Spring HTTP調用器使用標準Java序列化機制來通過HTTP暴露業務.
    但其配置與Burlap和Hessian很相近

    服務器端配置:
    <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) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 国产免费一区二区三区在线观看| 亚洲熟妇无码一区二区三区 | 亚洲av无码一区二区乱子伦as| 新最免费影视大全在线播放| 免费人成网站在线播放| 精品视频免费在线| 亚洲国产精品综合久久一线| 美女一级毛片免费观看| 亚洲精品成人在线| 中国一级全黄的免费观看| 久久亚洲综合色一区二区三区| 成人电影在线免费观看| 亚洲国产精品婷婷久久| 成年人免费的视频| 亚洲人成人无码.www石榴| 99re免费视频| 亚洲图片中文字幕| 蜜臀91精品国产免费观看| 黄色大片免费网站| 久久久久亚洲AV无码专区桃色| 老司机69精品成免费视频| 亚洲一卡2卡4卡5卡6卡残暴在线| 成年在线网站免费观看无广告| 色噜噜噜噜亚洲第一| 国产日本一线在线观看免费| 亚洲国产成人精品无码区二本| 成人亚洲综合天堂| 全免费a级毛片免费看| 99热亚洲色精品国产88| 亚洲 小说区 图片区 都市| 男女午夜24式免费视频| 亚洲区日韩精品中文字幕| 亚洲精品和日本精品| 免费国产黄网站在线观看 | 亚洲精品欧洲精品| 日韩免费电影在线观看| a级毛片无码免费真人久久| 亚洲国产成人九九综合| 无码不卡亚洲成?人片| 毛片免费全部播放无码| 香港特级三A毛片免费观看|