Groovy makes spring much better, part 1th: Fundamentals of Integration

Source: Internet
Author: User
Tags file system

See how Groovy can increase the flexibility of Spring based applications

Introduction: The Spring Framework provides a solid foundation for WEB and enterprise applications. By supporting dynamic languages such as Groovy, Spring adds features that make the application architecture more flexible and dynamic. In the first installment of the 2-part series, you'll learn the basics of integrating Groovy into a Spring application.

Spring 2.0 supports the integration of dynamic languages into spring based applications. Spring out-of-the-Box supports Groovy, JRuby, and BeanShell. Parts of the application written in Groovy, JRuby, or any supported language (including the Java™ language, of course) can be seamlessly integrated into the Spring application. Code in other parts of the application does not need to know or care about the implementation language of a single Spring bean.

Spring's support for dynamic languages means that applications can be flexible and dynamic and without any additional conditions. In part 1th of this series, you'll see how to use Spring and Groovy, and how this powerful integration adds interesting functionality to your application. For example, you may need to frequently change the business logic of a small block, the text contained in an e-mail message sent by your application, the PDF format and layout that your application generates, and so on. In order to make changes, the traditional application architecture may require a full redeployment of the application. After Spring supports Groovy, you can change a deployed application and make those changes take effect immediately. I'll discuss the benefits of this feature for the application and the problems that might arise. The complete source code for all the examples in this article (see download) is available for download.

Spring's Dynamic language support

Dynamic language support transforms Spring from a Java-centric application framework into a JVM-centric application framework. Now, Spring is no longer just making Java development easier. It also allows easy insertion of code written in static and dynamic languages into the layered architectural approach supported by Spring, making it easier to develop the JVM. If you are already familiar with Spring, then you feel comfortable: You can take advantage of all the features Spring has already provided-control inversion (IoC) and dependency injection, aspect-oriented programming (AOP), declarative transaction partitioning, WEB and data access framework integration, remote invocation, and so on-while you can use spiritual activity Language, such as Groovy.

Spring supports dynamic language integration through the scriptfactory and Scriptsource interfaces. The Scriptfactory interface defines the mechanism used to create and configure a script Spring bean. Theoretically, all languages running on the JVM are supported, so you can choose a specific language to create your own implementation. Scriptsource defines how Spring accesses the actual script source code, for example, through a file system or a URL. Groovy language integration is supported through Scriptfactory groovyscriptfactory implementations.

Why is Groovy?

According to the official groovy site, groovy is "an agile dynamic language for Java virtual machines", which "builds on the power of Java and includes powerful additional features from languages such as Python, Ruby, and Smalltalk", such as dynamic classes Type conversion, closures, and metaprogramming (metaprogramming) support (see Resources). It is a mature object-oriented programming language that can be used both for object-oriented programming and as a pure scripting language. I like to view it as a Java language with no annoying code, but with other features in closures and dynamic languages.

Groovy is particularly well suited to use with Spring's dynamic language support because it is designed for the JVM and is designed with full consideration for Java integration, which makes Groovy's interoperability with Java code easy. Its Java-like syntax is also natural for Java developers.

Next, see how you can integrate Groovy code into a Spring based application.

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.