25 Jun 2020
Host multiple Web sites from one S3 bucket using one CloudFront distribution

[ aws  cloudfront  s3  spa  webapp  ] Here’s how you can host multiple Web sites with custom domain names from a single S3 bucket using a single CloudFront distribution. For example: x.foo.com > My CloudFront Distribution > s3://my-bucket/x.foo.com y.foo.com > My Cloud...

06 Jul 2019
Hello World

[ github  jekyll  ] Hello World. This is the first post since I decided to cancel my Wordpress blog. This new blog solution is hosted on GitHub and generated with Jekyll. I hope that I get the time to import my old blog posts over the next weeks.

08 Sep 2018
Spring: Ignoring mocks

[ java  spring  spring-boot  unit-test  ] If you are using the core Spring Framework (that is, not Spring Boot), then you may have encountered a problem where Spring doesn’t seem to completely ignore mocked beans in your tests: Perhaps Spring attempts to inject beans into them or run your...

24 Jul 2017
Spring 4.3: Using a TaskDecorator to copy MDC data to @Async threads

[ java  spring  spring-boot  @async  mdc  logging  ] In this post I am going to show how to copy MDC data from Web threads to @Async threads using a brand new Spring Framework 4.3 feature: ThreadPoolTaskExecutor#setTaskDecorator() [set-task-decorator]. This is the end result: Notice the third an...

26 Mar 2017
Kotlin: Understanding properties

[ kotlin  ] In this post I am going to look into Kotlin properties [1] from a Java developers perspective. By a few examples and by looking into the generated code. I have created an example project on GitHub. You will find a few examples of how to declare p...

19 Mar 2017
Spring Boot: A bit more cool with Kotlin

[ kotlin  spring  spring-boot  ] In the context of my favorite framework, Spring Boot, I have recently started to explore the effect of using the Kotlin 1.1 programming language (as an alternative to Java 8). This post describes a few language features that may be interesting to ...

16 Mar 2017
Java EE: Hello World, Kotlin

[ java  javaee  ejb  kotlin  jax-rs  arquillian  integration-test  ] Are you a savvy Java EE 7 application developer? My bet is then, that you are using Java 7/8 for developing your favorite components (EJBs, CDI beans etc). In this post I am going to show how you can develop a Java EE 7 application using Kotlin 1....

12 Mar 2017
Spring Boot: Hello World, Kotlin

[ kotlin  spring  spring-boot  ] In this post I show how you can create a Spring Boot 1.5 application using Kotlin 1.1 (as opposed to typically Java 8 in these times). The example I’ve created is a typical “Hello World” example. I have chosen to implement a Spring MVC controller...

06 Feb 2017
Spring Boot: Prometheus actuator endpoint

[ java  spring  spring-boot  prometheus  spring-boot-actuator  ] In this post I show how you can add support for Prometheus in Spring Boot applications. Step 1 of 2: Add the Prometheus Spring Boot Starter You can get Prometheus support in Spring Boot applications via a so-called “starter”. Here is how to get t...

09 Nov 2016
Spring Boot: Controlling timezones with Hibernate

[ java  spring  spring-boot  hibernate  jpa  ] In this post I show how you, from a Spring Boot application, can control the timezone used by Hibernate when it communicates timestamps with the database. This post is inspired by a very similar recent post by Vlad Mihalcea [1], Hibernate Develope...

23 Oct 2016
Spring: Bean qualification

[ java  spring  bean-qualification  ] In this post I present how you can control a situation in which there are multiple beans that qualifies for an injection point in Spring. The material here has been tested with Spring Framework 4.3. The problem Let’s first take a look at the pro...

22 Oct 2016
Spring Boot and Gradle: Separating tests

[ java  spring  unit-test  integration-test  gradle  ] In this post I will present 4 different approaches to separating unit tests from integration tests, so that they can be run independently of each other. Here’s the 4 different approaches: Separation based on name patterns Separation based on...

15 Oct 2016
Spring Boot: Gherkin tests

[ java  spring  spring-boot  unit-test  integration-test  gherkin-test  bdd  ] In this post I show how you can implement Gherkin tests for Spring Boot 1.4.1. Here is an example of a Gherkin based test script: The Feature, Scenario, Scenario Outline, Given, When, Then and And constructs are part of the Gherkin test languag...

15 Oct 2016
Spring 4.3: Custom annotations

[ java  spring  spring-stereotype  annotation  ] In this post I will show you how to bend the Spring Framework a little bit. In particular I will show you how you can make code like this: 1 2 3 4 5 6 7 8 9 10 11 @BusinessService public class GreeterService { @LocalizedMessage("greeterservice...

09 Oct 2016
Spring 4.3: Introducing the InjectionPoint class

[ java  spring  spring-boot  annotation  injection-point  ] Did you know that Spring Framework 4.3 comes with a ”hidden” gem: the InjectionPoint class? At the time of writing this post, InjectionPoint is nowhere to be found in the Spring Framework Reference Documentation [2]. About the InjectionPoint cla...

30 Aug 2016
Java: Custom logger factory that automatically infers the class name

[ java  logging  ] In this post I show how you can declare loggers like this: 1 2 3 public class MyService { private static final Logger LOG = MyLoggerFactory.getLogger(); } There is no argument to the MyLoggerFactory::getLogger method. Contrast that to the n...

24 Aug 2016
Spring Boot: Show all logging events for one Web request only

[ java  spring  spring-boot  logging  trace  http-request  ] In this post I show how you for a single Web request can make your Spring Boot application dump all log statements on all categories (TRACE, DEBUG, INFO, WARN, ERROR). Everything - but only for the specific Web request that you care about. I show ...

22 Aug 2016
Spring Boot: Sessions actuator endpoint

[ java  spring  spring-boot  spring-boot-actuator  trace  http-session  ] This post shows how you can implement a custom Spring Boot Actuator endpoint that prints information about all active HttpSessions: HttpSession meta data is prefixed with @ signs: id, creation time and last accessed time. The other values are a...

18 Aug 2016
Spring Boot: Introduce your own insight endpoints

[ java  spring  spring-boot  spring-boot-actuator  ] In this post I show how you can develop custom Spring Boot Actuator HTTP endpoints for obtaining detailed insight into your Spring Boot application’s runtime behavior. Here’s an example: The above output is simple. Yet it can be useful to have...

16 Aug 2016
Spring Boot: Enhance your thread dumps

[ java  spring  spring-boot  spring-boot-actuator  thread-dump  ] In this post I show how you can add extra information to your applications’ thread dumps. I will use Spring Boot as an example environment - but the idea is very generic: You can, for example, easily apply this technique to any other Java EE appl...

16 Aug 2016
Spring Boot: Enhance your logging

[ java  spring  spring-boot  logging  mdc  slf4j  ] In this post I show how you can tune your Spring Boot application’s logging output - such that it has even more information when you need to troubleshoot. The method is actually so generic that you can apply it to other types of Java applications ...

14 Aug 2016
Spring Boot: Custom auto-configuration JARs

[ java  spring  spring-boot  spring-boot-autoconfiguration  ] Custom auto-configuration JAR: A shared JAR module containing Spring beans that can be automatically activated in one or more Spring Boot applications. Auto-configuration JARs are extensively used by the official Spring Boot starter modules you a...

12 Aug 2016
Spring Boot: UI for the dump endpoint

[ java  spring  spring-boot  spring-boot-actuator  dump-endpoint  thread-dump  ] I am really happy with the actuator functionality in Spring Boot applications. It offers some fantastic tools for gaining insight into your application. Some of the REST endpoints that you get - such as health and metrics - are easy to read. Despi...

12 Aug 2016
Arquillian: Testing legacy applications

[ java  javaee  ejb  integration-test  arquillian  legacy-app  ] This post describes a technique that my previous colleagues and I successfully used for integration testing a large and complex legacy Java EE 7 application (EAR file). The tests were successfully implemented using Arquillian along with a few Wild...

10 Aug 2016
Spring 5: Gets reactive

[ java  spring  reactive-programming  ] Spring 5 is going to include support for the reactive programming model [1]. Here’s an example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import org.springframework.http.MediaType; import org.springframework.http.client.reactive.R...