Chapter 9. Integrating with Spring and Hibernate/JPA

 

This chapter covers

  • Managing objects with Spring
  • Knowing when to use dependency injection
  • Adding Spring to Struts 2
  • Integrating Struts 2 and the Java Persistence API

Now that we’ve finished the core chapters, we know how to build a basic Struts 2 application. We’ve even done so with our Struts 2 Portfolio. This chapter starts the part of the book dealing with how to finish the application with a variety of refinements that many developers consider best practices. The refinements that we introduce in this chapter are specifically related to integrating a Struts 2 application with a pair of popular third-party technologies, Spring and the Java Persistence API (JPA).

First, we learn how to use a Spring container to provide a more sophisticated means of managing our application resources. While Spring provides many different services to the application developer, we focus here on the use of Spring as a means of dependency injection. In short, we use Spring to intervene in the creation of both framework and application objects for the purpose of injecting dependencies into those objects. We both explain what this means and demonstrate the details by upgrading our Struts 2 Portfolio to use Spring for such purposes as injecting our service object into the actions that require it.

9.1. Why use Spring with Struts 2?

9.2. Adding Spring to Struts 2

9.3. Why use the Java Persistence API with Struts 2?

9.4. Summary