Mastering Spring MVC 4

Book Description

Gain expertise in designing real-world web applications using the Spring MVC framework

About This Book

  • Design your own Spring web applications using tools such as Spring Boot and Spring Tool Suite
  • Secure your developments with easy-to-write, reliable unit and end-to-end tests
  • Deploy your application on the cloud for free and invite the whole world to see

Who This Book Is For

This book is perfect for developers who are familiar with the fundamentals of Spring programming and are eager to deepen their web development skills. Prior knowledge of the Spring MVC framework is recommended.

What You Will Learn

  • Set up your own web application using Spring Boot and Spring Tool Suite
  • Discover the MVC architecture and the different tools along with navigating between views
  • Design complex advanced-level forms and validate the model
  • Craft a RESTful application with a meaningful API and error messages
  • Create maintainable unit and acceptance tests
  • Secure your application while allowing it to scale
  • Optimize your requests with caching, ETags, and asynchronous responses
  • Deploy the web application to the cloud in a snap

In Detail

Spring MVC is the ideal tool to build modern web applications on the server side. With the arrival of Spring Boot, developers can really focus on the code and deliver great value, leveraging the rich Spring ecosystem with minimal configuration.

Spring makes it simple to create RESTful applications, interact with social services, communicate with modern databases, secure your system, and make your code modular and easy to test. It is also easy to deploy the result on different cloud providers.

Mastering Spring MVC will take you on a journey from developing your own web application to uploading it on the cloud.

You begin by generating your own Spring project using Spring Tool suite and Spring Boot.

As you develop an advanced-level interactive application that can handle file uploads as well as complex URLs, you will dive into the inner workings of Spring MVC and the principles of modern web architectures.

You will then test, secure, and optimize your Spring web application and design RESTful services that will be consumed on the frontend.

Finally, when everything is ready, you will release your application on a cloud provider and invite everyone to see.

Style and approach

An iterative hands-on approach in a conversational and easy-to-follow style. Each chapter will improve on the work done in the previous one until the application is ready to be released.

Publisher Resources

Download Example Code

Table of Contents

  1. Mastering Spring MVC 4
    1. Table of Contents
    2. Mastering Spring MVC 4
    3. Credits
    4. About the Author
    5. About the Reviewers
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Setting Up a Spring Web Application in No Time
      1. Getting started with Spring Tool Suite
      2. Getting started with IntelliJ
      3. Getting started with
        1. Getting started with the command line
      4. Let's get started
        1. The Gradle build
        2. Let me see the code!
      5. Spring Boot behind the curtains
        1. The dispatcher and multipart configuration
        2. The view resolver, static resources, and locale configuration
      6. Error and encoding configuration
      7. Embedded Servlet container (Tomcat) configuration
        1. The HTTP port
        2. The SSL configuration
        3. Other configurations
      8. Summary
    9. 2. Mastering the MVC Architecture
      1. The MVC architecture
      2. MVC critics and best practices
        1. Anemic Domain Model
        2. Learning from the sources
      3. Spring MVC 1-0-1
      4. Using Thymeleaf
        1. Our first page
      5. Spring MVC architecture
        1. DispatcherServlet
        2. Passing data to the view
      6. Spring Expression Language
        1. Getting data with a request parameter
      7. Enough Hello Worlds, let's fetch tweets!
        1. Registering your application
        2. Setting up Spring Social Twitter
        3. Accessing Twitter
      8. Java 8 streams and lambdas
      9. Material design with WebJars
        1. Using layouts
        2. Navigation
      10. The check point
      11. Summary
    10. 3. Handling Forms and Complex URL Mapping
      1. The profile page – a form
      2. Validation
        1. Customize validation messages
        2. Custom annotation for validation
      3. Internationalization
        1. Changing the locale
        2. Translating the application text
        3. A list in a form
      4. Client validation
      5. The check point
      6. Summary
    11. 4. File Upload and Error Handling
      1. Uploading a file
        1. Writing an image to the response
        2. Managing upload properties
        3. Displaying the uploaded picture
        4. Handling file upload errors
      2. Translating the error messages
      3. Placing the profile in a session
      4. Custom error pages
      5. URL mapping with matrix variables
      6. Putting it together
      7. The check point
      8. Summary
    12. 5. Crafting a RESTful Application
      1. What is REST?
      2. Richardson's maturity model
        1. Level 0 – HTTP
        2. Level 1 – Resources
        3. Level 2 – HTTP verbs
        4. Level 3 – Hypermedia controls
      3. API versioning
      4. Useful HTTP codes
      5. Client is the king
      6. Debugging a RESTful API
        1. A JSON formatting extension
        2. A RESTful client in your browser
        3. httpie
      7. Customizing the JSON output
      8. A user management API
      9. Status codes and exception handling
        1. Status code with ResponseEntity
        2. Status codes with exceptions
      10. Documentation with Swagger
      11. Generating XML
      12. The check point
      13. Summary
    13. 6. Securing Your Application
      1. Basic authentication
        1. Authorized users
        2. Authorized URLs
        3. Thymeleaf security tags
      2. The login form
      3. Twitter authentication
        1. Setting up social authentication
        2. Explanation
      4. Distributed sessions
      5. SSL
        1. Generating a self-signed certificate
        2. The easy way
        3. The dual way
        4. Behind a secured server
      6. The check point
      7. Summary
    14. 7. Leaving Nothing to Luck – Unit Tests and Acceptance Tests
      1. Why should I test my code?
      2. How should I test my code?
      3. Test-driven development
      4. The unit tests
        1. The right tools for the job
      5. The acceptance tests
      6. Our first unit test
      7. Mocks and stubs
        1. Mocking with Mockito
        2. Stubbing our beans while testing
        3. Should I use mocks or stubs?
      8. Unit testing REST controllers
      9. Testing the authentication
      10. Writing acceptance tests
        1. The Gradle configuration
        2. Our first FluentLenium test
        3. Page Objects with FluentLenium
        4. Making our tests more Groovy
        5. Unit tests with Spock
        6. Integration tests with Geb
        7. Page Objects with Geb
      11. The check point
      12. Summary
    15. 8. Optimizing Your Requests
      1. A production profile
      2. Gzipping
      3. Cache control
      4. Application cache
        1. Cache invalidation
        2. Distributed cache
      5. Async methods
      6. ETags
      7. WebSockets
      8. The check point
      9. Summary
    16. 9. Deploying Your Web Application to the Cloud
      1. Choosing your host
        1. Cloud Foundry
        2. OpenShift
        3. Heroku
      2. Deploying your web application to Pivotal Web Services
        1. Installing the Cloud Foundry CLI tools
        2. Assembling the application
        3. Activating Redis
      3. Deploying your web application on Heroku
        1. Installing the tools
        2. Setting up the application
          1. Gradle
          2. Procfile
        3. A Heroku profile
        4. Running your application
        5. Activating Redis
      4. Improving your application
      5. Summary
    17. 10. Beyond Spring Web
      1. The Spring ecosystem
        1. Core
        2. Execution
        3. Data
        4. Other noteworthy projects
      2. The deployment
        1. Docker
      3. Single Page Applications
        1. The players
        2. The future
        3. Going stateless
      4. Summary
    18. Index

Product Information

  • Title: Mastering Spring MVC 4
  • Author(s): Geoffroy Warin
  • Release date: September 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781783982387