concept Spring in category grails

appears as: Spring
Grails in Action, Second Edition

This is an excerpt from Manning's book Grails in Action, Second Edition.

Building on Spring and Hibernate also means there’s no new magic going on under the hood if you need to tweak things in the configuration (by customizing a Hibernate configuration class) or at runtime (by getting a handle to a Spring Application-Context). None of your learning time on Spring and Hibernate is wasted.

It doesn’t matter if you’re new to Grails and don’t have a background in Spring or Hibernate. Few Grails development cases fall back to that level, but know it’s there if you need it.

The reason Grails works so well in this area is that it’s built on top of the incredibly popular and powerful Spring framework. We mentioned it in passing a few times, and it tends to remain invisible when your Grails applications don’t have complex business logic. You happily rely on services being automatically injected into your controllers and other artifacts. Yet when an application does increase in complexity, you won’t want to miss out on the help Spring can provide.

Understanding the basics of Spring is essential to writing flexible and maintainable Grails applications. Fortunately, Grails gives you a gradual learning curve to Spring that we take advantage of in this chapter to dig deeper and tease out the key features that will help you day to day. We also look at maintaining data integrity through transactions, which is one of the core features of Spring.

As you saw, Spring is a fundamental part of Grails, and although you can happily develop simple applications without ever being aware of its existence, you should take advantage of it as your application grows. Fortunately, this is easily done with services and the automatic DI that Grails provides.

When you start using Java libraries and integrating your application with other Java systems, you find that services don’t help. For the integration to work well, you have to define your own beans using the resources.xml and resources.groovy files, so that they can be easily slotted into the various Grails artifacts. If you do this type of integration, we recommend you become more familiar with Spring itself, either through the online documentation or a book. The framework contains far more than the classes related to the core IoC container.

Grails transaction support is one example of other features Spring brings to the table, and you saw how easy they are to use. If you write an application that performs updates to a database, you ought to familiarize yourself with transactions and the effects they have on reliably saving and modifying domain objects.