Introduction It has been almost 10 years now since I taught my first Core Spring class. At that time almost everything was XML and configuring JPA or Spring Security, for example, could be a lot of hard work. Spring has matured a great deal in the meantime with component-scanning, Java Configuration and Spring Boot making it much more fun to use. And the number of Spring Projects has increased considerably. Pivotal Training continues to enhance our Spring curriculum and introduce new courses - including Spring Boot Developer and Spring Cloud Services. I have provided an overview of these…
This blog has been updated -- see here. More Information For more information and to view our complete portfolio of Application Framework, Cloud Native and Big Data Suite classes, visit us at the Pivotal Academy.
Introduction NOTE: Revised July 2019 A simple example of setting up a microservices system using Spring, Spring Boot and Spring Cloud. Microservices allow large systems to be built up from a number of collaborating components. It does at the process level what Spring has always done at the component level: loosely coupled processes instead of loosely coupled components. For example imagine an online shop with separate microservices for user-accounts, product-catalog order-processing and shopping carts: Inevitably there are a number of moving parts that you have to setup and configure to…
NOTE: Revised April 2018 Spring MVC provides several complimentary approaches to exception handling but, when teaching Spring MVC, I often find that my students are confused or not comfortable with them. Today I'm going to show you the various options available. Our goal is to not handle exceptions explicitly in Controller methods where possible. They are a cross-cutting concern better handled separately in dedicated code. There are three options: per exception, per controller or globally. A demonstration application that shows the points discussed here can be found at
http://github.com…
In my previous post I introduced the concept of content negotiation and the three strategies Spring MVC uses to determine the content requested. In this post I want to extend the concept specifically to supporting multiple views for different content-types using the ContentNegotiatingViewResolver (or CNVR). Since we already know how to setup content-negotiation from the previous post, using it to select between multiple views is very straightforward. Simply define a CNVR like this: For every request, a @Controller would typically return a logical view name (or Spring MVC will determine one…
There are two ways to generate output using Spring MVC: In either case you'll need to deal with multiple representations (or views) of the same data returned by the controller. Working out which data format to return is called Content Negotiation. There are three situations where we need to know what type of data-format to send in the HTTP response: Determining what format the user has requested relies on a ContentNegotationStrategy. There are default implementations available out of the box, but you can also implement your own if you wish. In this post I want to discuss how to configure and…