Benefits of Using Spring


By now, you should have a pretty good idea about what Spring is, how it is logically organized (into modules), and the types of functionality it provides. Although the benefits may appear somewhat obvious, the following is an explicit list:

  • POJOs My favorite benefit is that Spring enables me to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product such as an application server if your application doesn't require all the capabilities that such products provide. With Spring, you have the option of using only a robust servlet container such as Tomcat or some commercial product.

  • Modular As we have already discussed, Spring is organized in a modular fashion. Even though the number of packages and classes is substantial, you have to worry only about ones you need (see the sidebar "Overwhelmed by the Size of the Spring Framework?"). Hence, phasing Spring into an existing or new project can be done on a case-by-case and module-by-module basis.

  • Complementary I like the fact that Spring does not reinvent the wheel; instead, it truly complements some of the existing work out there. For example, it complements several ORM frameworks, JEE, Quartz and JDK timers, other view technologies, and more.

  • Testing Testing an application written with Spring is simple because environment-dependent code is moved into this framework (versus JNDI lookups embedded in code, for example). Furthermore, by using JavaBean-style POJOs, it becomes easier to use dependency injection for injecting test data (perhaps by using an XML file as the source of test data). In addition, Spring's mock classes can help you simulate classes such as an HTTP request object. This is primarily true because dependency injection works with setter and getter methods. Hence it is easy to inject test data into your objects and unit test your code using a product such as JUnit. This also includes testing of web components developed using Spring's web MVC framework, as you will see in the next chapter.

  • Singletons Spring eliminates the need to maintain your own singleton classes. Instead, you write a class as a normal POJO (without the need for static variables/methods), and Spring ensures that you always get access to the same object, unless you override the default by defining a class as nonsingleton.

  • Web framework Spring's web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other overengineered or less popular web frameworks. It enables you to develop no-form screens, simple-form screens, wizardlike screens, and much more. It can also bind HTML form fields directly to the business objects instead of having to write custom classes that extend the web framework's classes. Spring Web MVC is also view agnostic, so it can work with JavaServer Pages (JSP), Velocity, JavaServer Faces (JSF), and others. In addition, the Spring Web Flow subproject can be used to develop web applications that require state management across several HTTP requests (an online airline-booking website, for example).

  • Consistent exception hierarchy Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions (org.springframework.dao. PessimisticLockingFailureException, for example).

  • Enterprise-class transaction management Spring provides a consistent transaction management interface that can scale down to a local transaction (using a single database, for example) and scale up to global transactions (using JTA, for example). Spring also provides application server-specific integration, for instance, with BEA's WebLogic Server and IBM's WebSphere. Spring's transaction management can be used programmatically or declaratively. We will use the declarative version in Chapter 10.

  • Lightweight container IoC containers tend to be lightweight, especially when compared to EJB containers, for example. This can be beneficial, perhaps for developing and deploying applications on computers with limited memory and CPU resources.

We saw some of the benefits here, particularly ones that are applicable to Time Expression. However, if you decide to use Spring more extensively, you are likely to come up with your own list of benefits.



Agile Java Development with Spring, Hibernate and Eclipse
Agile Java Development with Spring, Hibernate and Eclipse
ISBN: 0672328968
EAN: 2147483647
Year: 2006
Pages: 219

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net