Topic 22
■■■
Scripting Support in Spring
In previous chapters, we saw how the Spring Framework can help Java developers create JEE
applications. By using the Spring Framework's DI mechanism and its integration with each layer (via
libraries within the Spring Framework's own modules or via integration with third-party libraries), you
can simplify implementing and maintaining business logic.
However, all the logic we have developed so far was with the Java language. Although one of the
most successful programming languages in history, Java is still criticized for some weaknesses, such as
its language structure or its lack of comprehensive support in areas like massive parallel processing.
For example, one feature of the Java language is that all variables are statically typed. In other words,
in a Java program, each variable declared should have a static type associated with it (in other words,
String, int, Object, ArrayList, and so on). However, in some scenarios, dynamic typing may be
preferred, which is supported by dynamic languages like JavaScript.
To address those requirements, many scripting languages have been developed. Some of the most
popular ones include JavaScript, Groovy, Scala, Ruby, and Erlang. Almost all of those languages support
dynamic typing and were designed to provide the features that are not available in Java, as well as
targeting specific purposes. For example, Scala (www.scala-lang.org) combines functional programming
patterns with OO patterns and supports a more comprehensive and scalable concurrent programming
model with concepts of actors and message passing. In addition, Groovy (http://groovy.codehaus.org)
provides a simplified programming model and supports the implementation of domain-specific
languages (DSLs) that make the application code easier to read and maintain.
One other important concept that those scripting languages bring to Java developers is closures
(which we will discuss in more detail later in this chapter). Simply speaking, a closure is a piece (or
block) of code wrapped in an object. It's executable like a Java method and can receive parameters and
return objects and values. In addition, it's also a normal object that can be passed with a reference
around your application, like any POJO in Java.
In this chapter, we will discuss some main concepts behind scripting languages, with the main focus
on Groovy; you'll see how the Spring Framework can work with scripting language seamlessly to provide
specific functionality to Spring-based applications. Specifically, this chapter will cover the following
topics:
Scripting support in Java: In JCP, JSR-223 (the Scripting for the Java Platform API)
·
enables the support of scripting languages in Java; it has been available in Java
since JSE 6. We will provide an overview of scripting support in Java.
Groovy: We will provide a high-level introduction to the Groovy language, which is
·
one of the most popular scripting languages being used with Java, specifically
using the Spring Framework.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home