Mattias Severson

Asynchronous Spring Service

It is not unusual that your web service needs to communicate with another web service in order to serve its clients. In the old days, that would imply that an incoming request to your server would capture one servlet connection, and perform a blocking call to the remote service before it can send a response to the client. It works, but it does not scale very well if you have multiple concurrent...

Spring Boot custom HealthIndicator

A big part of the DevOps responsibilities is to monitor and maintain the health of running servers. If a production server goes down, appropriate actions must be undertaken to bring the service back to life. However, before any resurrection, one must know that the server is malfunctioning in the first place. In an automated cloud environment, this can be handled by a load balancer calling a known...

Integration Testing a Spring Boot Application

Spring Boot brings about some welcome defaults configurations that significantly decreases the development time of Spring projects. It also has some useful additions when it comes to simplified integration testing. Traditionally, one would use the build script to fire up an embedded container such as Jetty, Tomcat or Cargo, but since a Spring Boot web application already comprises an embedded...

GeeCON 2014

Last week we visited the GeeCON conference in Krakow as speakers and participants. The event attracted some 1200 visitors according to the organizers, and it was located inside a cinema complex a few kilometers from the city centre, which means nice chairs and a large screens. In this blog we will present a short summary of some of the interesting talks. Testing & Deploying Microservices...

About ExecutorServices

Dealing with asynchronous programming is not easy, at least not if you are a Java programmer. Not only do you have to take care of Callables, Runnables, Futures and likes, you also need to configure the details of how they should be executed by providing an ExecutorService. The Executors class provides some static factory methods that can be used, at the expense of being less...

Spring @PropertySource

If you are a Spring developer and and you have created a Java based container configuration, you have probably come across the @PropertySource annotation for importing resources. It was first added as part of Spring 3.1, but Spring 4 has added some welcome improvements. Basics Let's start with a simple example: [crayon-54191c6f3ce50879823087/] When executed, properties will be imported from...

Spring and Autowiring of Generic Types

Spring 4 brings some nice improvements to how autowiring of generic types are handled. Before going into details, let's look into the current state of affairs. Basics Consider the following example where you have one generic interface: [crayon-54191c6f3e1d2633768998/] And two concrete implementations of it: [crayon-54191c6f3e1df092327242/] [crayon-54191c6f3e1ef742278658/] Now, the task is...

Improve Your Spring REST API, Part IV

Spring 4 is around the corner. Milestone releases has been available for a while, the first release candidate was released earlier today, and the final release is expected before the end of this year. @RestController One new feature that has been added is the @RestController annotation, which provide some syntactic sugar to your controller. Take a look at the following code...

SpringOne 2GX 2013

Last week, I had the privilege of speaking at SpringOne 2GX in Santa Clara. As the name implies, the conference was focused around Spring, Groovy and Grails. The conference tagline was "The Spring Groovy, Grails & Cloud Event of the Year!", and I must admit that resonates well my personal experience, and I strongly encourage you to go next time if you have the opportunity. So what was so great...

Working Efficiently with Maven Modules

When working with Java you will sooner or later come across Maven and Maven modules. Before you start developing a new module feature, upstream modules need to be built, and before you finish you must build downstream modules to make sure that you have not broken any dependencies or tests. However, it is not always obvious how different modules relate to each other. If you just call mvn clean...

Getting started with Gradle

Did you know that there is a Java build system that does not use angle brackets? More and more projects are using Gradle as an integrated part of their development process. In short, Gradle provides a Groovy DSL for declarative builds based on build conventions. This blog post aims to give you a kickstart if you want to start exploring Gradle yourself by introducing some core concepts and...

Improve Your Spring REST API, Part III

Some time ago, I wrote about how the error response of a Spring based REST API can be enhanced, in order to provide the clients with a better understanding of why a request error occurred. In the first post I explained how a server-side exception triggered by an incoming request can be translated into a generic ErrorMessage class, which in turn was serialized to the response body. In the second...