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 problem. Imagine you have this interface: And two different implementations of this. First this: And then this:… Continue Reading
Latest Posts
-
-
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 JUnit categories Separation based on Spring’s @IfProfileValue Separation based on different source directories These approaches can easily be extended to apply… Continue Reading
-
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 language [1]. Such tests are popular in Behavior-driven development (BDD) and is meant as a common tool between… Continue Reading
-
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: @BusinessService declares a perfectly valid Spring bean. It comes with the support for @NotNull parameter checks. @NotNull is from the bean validation API – no need to exercise too many keystrokes. @LocalizedMessage is a perfectly valid injection capable annotation.… Continue Reading
-
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 class The InjectionPoint class [1] is a new feature that you can use in @Bean producer methods. It is specifically useful in @Bean methods that produces prototype scoped beans.… Continue Reading
-
In this post I show how you can declare loggers like this: There is no argument to the MyLoggerFactory::getLogger method. Contrast that to the normal way to declare a logger: This is business as usual. But have you ever made that silly mistake where you copy/paste a class – and then, in the new class,… Continue Reading
-
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 the technique using Spring Boot 1.4. Here’s an example. Imagine a call… Continue Reading