Spring Background






Spring Background

Spring provides a consistent, light-weight framework for building JSP-based applications based on the familiar MVC pattern:
  1. model (data)
  2. view (html page layout)
  3. controller (code to populate the view with model data, and respond to user input to read/update the model, and move to new pages)
  4. Business Logic (typically services, though replaced here by Automated Business Logic)

This project was created in SpringSourceToolSuite (STS) - a variation of Eclipse.


Spring Elements

The key elements are described below.

View .jsp (html markup)

You define the view elements as .jsp html markup.  A view associates itself with a controller with markup such as in line ??:


This sample required about 40 lines of markup.

Controller and Service

You then code Java controllers that are responsible for acquiring the data to push into the page, and invoking services to retrieve new data, update data, and/or move to a new view.  We might term this Presentation Business Logic.

The service is responsible for assuring that updates invoke Transaction Business Logic.  It is an anti-pattern to place this logic inside the controller - it should be architected for sharing between controllers and other transaction sources (e.g., message), perhaps in a service.

In a typical database update page, you might expect to find about half of the code as Presentation Business Logic, and half as Transaction Business Logic.  In this case, there was nearly 300 lines of Presentation Business Logic.  Using traditional approaches, there would also have been about 500 lines of Transaction Business Logic, though there was none in this case per Automated Business Logic.



Model: Hibernate Domain Objects

Spring is agnostic about how you obtain the model data the controller users to populate the view.  In this example, we used Hibernate/JPA.  Note the persistence.xml performs the standard bindings, with the addition of line 20 which plugs the Business Logic Engine into Hibernate/JPA events.



Transaction Business Logic

As described above, we specified the Transaction Business Logic as shown below, replacing 500 lines of Java code.  This is explained in the video on the parent page.




Comments