When spring encounters Ruby

Source: Internet
Author: User
Author: Jiangnan Baiyi

When Wang Jiawei met du Kefeng and spring met Ruby. The crraig Wils that came up with this question is definitely a gossip, promoting spring 2. feature integrated with dynamic languages.

This feature aims to enable classes written in dynamic languages to be well integrated into the big framework of Java/spring, and be whitewashed into a common member in the application context, it has good interaction and injection capabilities with other pojo and can be exported to various services by DWR, xfire, and quartz.

Very simple, the/springside-bookstore/src/.../plugins/WebService/applicationContext-webservice-client.xml file in springside shows all usage.

<? 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>

Note that spring 2.0 provides the <LANG: Language> shorthand for language integration. For details, see chapter 24th of spring reference documentation.

The first property, refresh-check-delay, is used to scan script changes and reload it at intervals.

The second property script-source points to scriptsouce. <LANG: Property> interprets spring's favorite IOC and injects the serviceur variable.

Of course, there is no miracle in the world. Spring and groovy and jruby use an interface to define the connection points. When spring uses bookserviceclient bean, it actually uses the bookservice interface. Groovy is a close cousin of Java, so you can directly implements bookservice interface in the class, while jruby must pass interface as a construction parameter to rubyscriptfactory. In this way, we have to explicitly define all functions, parameters, and return value types of interfaces in groovy. Ruby's Miss method and groovy's mop reflection are useless.
The stage has been set up and the boundaries have been blurred. Next we will look at everyone's imagination like AOP.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.