Spring Team
Paul Chapman

Paul Chapman

Senior Consultant Trainer


Working with Spring and Pivotal products since 2007, Dr. Paul Chapman is a Senior Consultant within our APJ service delivery division, where he undertakes consulting, training and mentoring of our clients across Asia-Pacific. Paul specializes in architecting, developing and managing distributed, enterprise Java systems, cloud-native applications and microservices, especially on Pivotal Cloud Foundry.
Blog Posts by Paul Chapman

Pivotal Announces Spring Curriculum & Certification Changes


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 courses and some of the newest features below. Most importantly, how you obtain Certification has changed.


Microservices with Spring


NOTE: Revised June 2018

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.

Shopping Application

For example imagine an online shop with separate microservices for user-accounts, product-catalog order-processing and shopping carts:


Exception Handling in Spring MVC

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/paulc4/mvc-exceptions. See Sample Application below for details.


Content Negotiation using Views

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).

Quick Overview

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:

<!-- // View resolver that delegates to other view resolvers based on the // content type --> <bean class="org.springframework.web.servlet.view. ContentNegotiatingViewResolver"> <!-- All configuration now done by manager - since Spring V3.2 --> <property name="contentNegotiationManager" ref="cnManager"/> </bean> <!-- // Setup a simple strategy: // 1. Only path extension is taken into account, Accept headers // are ignored. // 2. Return HTML by default when not sure. --> <bean id="cnManager" class="org.springframework.web.accept. ContentNegotiationManagerFactoryBean"> <property name="ignoreAcceptHeader" value="true"/> <property name="defaultContentType" value="text/html" /> </bean>

Content Negotiation using Spring MVC

There are two ways to generate output using Spring MVC:

  • You can use the RESTful @ResponseBody approach and HTTP message converters, typically to return data-formats like JSON or XML. Programmatic clients, mobile apps and AJAX enabled browsers are the usual clients.
  • Alternatively you may use view resolution. Although views are perfectly capable of generating JSON and XML if you wish (more on that in my next post), views are normally used to generate presentation formats like HTML for a traditional web-application.
  • Actually there is a third possibility - some applications require both, and Spring MVC supports such combinations easily. We will come back to that right at the end.