Chapter 2. Building the Web Layer with Spring Web MVC

Web application development is a major focus area for enterprise systems. In this age of cloud and big data, web applications are under a tremendous load of an ever-increasing number of concurrent users accessing them from multiple devices such as mobiles and tablets, as well as traditional desktop web browsers. Modern web applications have to address a newer set of nonfunctional requirements, such as scalability, performance, productivity, responsiveness, and multi-device support.

Spring MVC is a web framework from Spring, perfectly built from the ground up to address the concerns of modern web applications. A lightweight and high-performance web framework, Spring MVC is designed to be highly productive from day one, flexible, and adaptable with a wide variety of view technologies. Sitting on top of the mighty Spring Framework, it integrates well with all Java EE technologies and other open source frameworks. Just like any technology under the Spring portfolio, Spring MVC also promotes POJO programming with the help of a well-defined set of annotations, namespace XML tags, and web-support components.

This chapter introduces Spring MVC and its powerful features to you, describes how to set it up, and guides you on its advanced usages, configurations, and optimizations with relevant examples. We will mostly use annotations in these examples for simplicity. At the end of this chapter, you will be able to build web applications with Spring MVC that have HTML-based user interfaces as well as RESTful APIs with JSON and XML formats.

Features of Spring MVC

Spring MVC bundles a compelling set of features and advantages over rival web technologies. Knowledge of these will help you decide on choosing Spring MVC for your requirements. The following list covers most of them:

  • Simple configuration and native integration with Spring Framework, leveraging the powerful features of Spring and other open source libraries
  • Built on top of Java web technologies such as Servlets, JSP, and JSTL and can be deployed into any standard Servlet container, such as Tomcat
  • Implemented based on the Model-View-Controller (MVC) architecture pattern, with clear separation of concerns using simple annotations and namespace XML tags
  • Explicit support for convention over configuration for MVC components
  • Supports a big set of view technologies, such as JSP, Thymeleaf, Handlebars, Velocity, FreeMarker, PDF, Excel, and JasperReports
  • Declarative input validation, data binding, and exception handling
  • Flexible URL mapping with automatic request and response transformation into various formats such as JSON, XML, and HTML
  • Support for non-blocking asynchronous request processing and HTTP streaming
  • Support for internationalization, themes, and multipart file uploads
  • Easy integration with Spring Security and thorough testability
  • HTTP caching for increased performance
  • A simple, yet powerful, JSP tag library

What makes Spring MVC outstanding is its simple programming model, a feature inherited from the core Spring Framework itself. A developer familiar with any standard web framework will find Spring MVC very familiar and easy to learn.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset