當Spring遇到Ruby

來源:互聯網
上載者:User
作者:江南白衣 

    當王家衛遇到杜可風,Spring遇到Ruby。想出這個題目的Crraig Walls 絕對也是個八卦種子,宣傳的是Spring 2.整合動態語言的feature。
     
     此Feature目的是讓動態語言編寫的類,可以良好的融入java/spring的大架構內,洗白成application context中的普通一員,擁有與其他pojo良好的互動與注入能力,可以被DWR,XFire,Quartz匯出成各式服務。

      很簡單,SpringSide 裡的/springside-bookstore/src/.../plugins/webservice/applicationContext-webservice-client.xml檔案已說明了一切用法。
   

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:lang="http://www.springframework.org/schema/lang"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd">

   <!--Groovy版本的Web Service Client-->
    <lang:groovy id="BookServiceClient"
             refresh-check-delay="60000"
             script-source="classpath:org/springside/bookstore/plugins/webservice/service/BookServiceClient.groovy">
           <lang:property  name="serviceUrl" value="http://localhost:8080/springside/service/BookService"/>
    </lang:groovy>
</beans>

    注意spring 2.0為語言整合提供了<lang:language>的簡寫法,詳細見Spring的參考文檔第24章  

    第一個屬性 refresh-check-delay,每隔一段時間掃描一次指令碼的變化,reload it。

   第二個屬性script-source 指向scriptsouce, <lang:property>演繹了Spring最喜愛的IOC,將serviceUr變數注入。

    當然,世上沒有奇蹟,Spring 與Groovy、JRuby 是靠一個Interface來定義連接點的。Spring使用BookServiceClient Bean 時,實際使用的是BookService介面。 Groovy因為是Java近親,所以可以在類裡面直接implements BookService介面,而JRuby則必須把interface作為構造參數傳給RubyScriptFactory。這樣有個不爽的地方,在Groovy裡必須顯式定義介面的所有函數和參數、傳回值的類型。Ruby的Miss Method與Groovy的MOP反射頓時沒了用武之地。
     舞台已經搭好,界限已經模糊,接下來就和AOP一樣,看大家的想象力了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.