Spring Team
Paul

Paul

Senior Consultant Trainer

Sydney

Working with Spring and Pivotal products since 2009, 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.
Blog Posts by Paul

Pivotal Academy Launches Updated Spring Classes

It has been 7 years now since I taught my first 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.

At every stage we have updated our Spring courses to reflect these changes and I am pleased to announce that our most popular Spring training courses - Core Spring, Spring Web and Enterprise Spring - have been revised to align with the latest Spring 4.2 release. These courses include much more Spring Boot material and expanded coverage of features like Spring Data, Spring HATEOAS, Spring MVC Websockets, Spring XD, Spring Cloud and microservices.

Read more...

Microservices with Spring

Introduction

NOTE: Revised 21 May 2016

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:

Read more...

Exception Handling in Spring MVC

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.

Read more...

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 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 is now done by the 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>
Read more...

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.
Read more...