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

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

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

    posts - 156,  comments - 601,  trackbacks - 0
    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>



    Good Luck!
    Yours Matthew!
    posted on 2008-11-02 19:20 x.matthew 閱讀(2513) 評論(1)  編輯  收藏 所屬分類: Spring|Hibernate|Other framework
    主站蜘蛛池模板: 亚洲国产成人久久精品影视 | 337P日本欧洲亚洲大胆精品| 久久久精品免费国产四虎| 国产精品亚洲产品一区二区三区| 免费一级毛片在线播放视频免费观看永久| 国产极品美女高潮抽搐免费网站| 亚洲AV无码专区在线观看成人 | 国产成人免费永久播放视频平台| 亚洲熟女乱色一区二区三区| 女人18毛片水真多免费播放| 亚洲精品无码你懂的| 国产成人免费A在线视频| 黄色一级毛片免费看| 国产日产亚洲系列| 野花香高清视频在线观看免费 | 国产精品成人免费视频网站京东| 97久久国产亚洲精品超碰热| 毛片免费观看网址| 国产成人亚洲精品蜜芽影院| 国产成人精品曰本亚洲79ren| 中国一级特黄高清免费的大片中国一级黄色片 | 亚洲成a人片在线不卡一二三区| 成人黄动漫画免费网站视频| 国产亚洲欧美在线观看| 日韩亚洲变态另类中文| 最刺激黄a大片免费网站| 中国亚洲呦女专区| 亚洲成人影院在线观看| 久久成人无码国产免费播放| 亚洲国产片在线观看| 国产一区二区三区免费看| 中文字幕不卡高清免费| 亚洲成人动漫在线观看| 免费一级毛片在级播放| 性色午夜视频免费男人的天堂| 亚洲综合偷自成人网第页色| 亚洲日韩国产精品乱| 四虎成年永久免费网站 | 中文字幕在线免费播放| 亚洲国产成人精品无码区在线秒播 | 亚洲第一黄片大全|