Understanding Callable and Spring DeferredResult

1 Introduction Asynchronous support introduced in Servlet 3.0 offers the possibility to process an HTTP request in another thread. This is specially interesting when you have a long running task, since while another thread processes this request, the container thread is freed and can continue…

Migrating Spring MVC RESTful web services to Spring 4

1 Introduction Spring 4 brings several improvements¬†for MVC applications. In this post I will focus on restful web services and try these improvements by performing a migration from Spring MVC 3.2 to Spring 4.0. We will take a project implemented with Spring 3.2 and perform…

Applying aspect oriented programming

1 Introduction This article explains how to apply aspect oriented programming with Spring AOP. The main target of the aspect oriented programming is the separation of cross-cutting concerns. When we talk about cross-cutting concerns we are referring to generic functionality that is used in several…

Centralize validation and exception handling with @ControllerAdvice

1 Introduction The ControllerAdvice annotation introduced by Spring 3.2 allows us to handle several functionalities in a way that can be shared by all controllers (through its handler methods, annotated with @RequestMapping). This annotation is mainly used to define the following methods: @ExceptionHandler: Handles exceptions…

Accessing Restful services. HTTP Message converters

Registered converters When accessing to Restful services, the Spring class RestTemplate maintains a list of message converters. This list will be used to marshal objects into the request body, or unmarshalling them from the response. When instantiating the RestTemplate class, it automatically fills a list…

Create and test REST services with Spring MVC

Introduction The first part of this example shows how to create and test REST services using Spring MVC. The controller contains CRUD operations on warehouses and its products. For this example, the repository is a stub that simulates access to the database. The second part…