Skip to content
Model centric tools for Spring development Community portal
Skyway PerspectivesModel driven delivery

Model reference

Reference Figure: The Complete MVC Application

All four layers in one view: the web layer, the controller layer, the service layer and the data layer, with the direction of dependency between them.

Four stacked application layers for Spring MVC and Spring Web Flow
Figure 8. The four layers of a generated application, from the view down to the data store.

A generated application is a stack of four layers. Each layer has one job and depends only on the layer below it. The clear direction of dependency is what makes the application testable and easy to extend.

The layers

  • View and UI layer. JSP pages and tags that render data and collect input.
  • Controller layer. Request handling, binding, validation and view selection.
  • Service layer. Transactions, business rules and calls to repositories.
  • Data layer. Entity types, repositories and named queries.

Why the stack matters

Because the layers only point downward, a change in the data layer does not force a change in the web layer. A new view can be added without touching the database. A service can be tested with a stub repository, and a controller can be tested with a stub service. Each test stays small and fast.

Design check. If a view calls a repository directly, or a controller contains SQL, a layer rule has been broken. Move the code back to the layer that owns it.

Use this figure as a map when you open an unfamiliar generated project. Start at the view, follow the controller, then read the service and the repository. The code will match the stack almost every time.