29-03-2012, 01:30 PM
Dynamic language support
Dynamic language support 23.docx (Size: 33.72 KB / Downloads: 25)
Introduction
Spring 2.0 introduces comprehensive support for using classes and objects that have been defined using a
dynamic language (such as JRuby) with Spring. This support allows you to write any number of classes in a
supported dynamic language, and have the Spring container transparently instantiate, configure and dependency
inject the resulting objects.
A first example
This bulk of this chapter is concerned with describing the dynamic language support in detail. Before diving
into all of the ins and outs of the dynamic language support, let's look at a quick example of a bean defined in a
dynamic language. The dynamic language for this first bean is Groovy (the basis of this example was taken
from the Spring test suite, so if you want to see equivalent examples in any of the other supported languages,
take a look at the source code).
Defining beans that are backed by dynamic languages
This section describes exactly how you define Spring managed beans in any of the supported dynamic
languages.
Please note that this chapter does not attempt to explain the syntax and idioms of the supported dynamic
languages. For example, if you want to use Groovy to write certain of the classes in your application, then the
assumption is that you already know Groovy. If you need further details about the dynamic languages
themselves, please consult the section entitled Section 24.6, “Further Resources” at the end of this chapter.
24.3.1. Common concepts
The steps involved in using dynamic-language-backed beans are as follows:
1. Write the test for the dynamic language source code (naturally)
2. Then write the dynamic language source code itself
3. Define your dynamic-language-backed beans using the appropriate <lang:language/> element in the XML
configuration (you can of course define such beans programmatically using the Spring API - although you
will have to consult the source code for directions on how to do this as this type of advanced configuration is
not covered in this chapter). Note this is an iterative step. You will need at least one bean definition per
dynamic language source file (although the same dynamic language source file can of course be referenced
by multiple bean definitions).