All posts by Daniel Olszewski

Spring Cloud – Basic setup

Spring Cloud solves common problems of distributed systems. However, for someone who works only with widely known monolith applications jumping into the long list of patterns designed for distributed services might be quite overwhelming at the very beginning. This article will take you through the basics of Spring Cloud by taking a practical approach. After finishing, not only should you know how to start a project based on Spring Cloud, but also understand why all steps are required and what problems they solve.

Continue reading Spring Cloud – Basic setup


Project package organization

The package is a fundamental concept in Java and one of the first things you stumble upon when starting programming in the language. As a beginner you probably don’t pay much attention to the structure of packages, but as you become a more experienced and mature software developer, you start to think what can be done to improve their efficiency. There are a few major options to consider and picking the right one might not be an obvious choice. This article should give you an overview of commonly selected strategies.

Continue reading Project package organization


7 reasons why you should start using JUnit 5 today

“He who moves not forward, goes backward.” ― Johann Wolfgang von Goethe

The latest version of JUnit is just around the corner. According to the official roadmap the final release is planned for Q3 2017. At the moment of writing, 4 milestones have been published and a few more are planned before release candidates, but it doesn’t mean you have to wait several months to make use of Junit 5. The goal of this post is to encourage you in seven points to start playing with the new version the framework right away.

Continue reading 7 reasons why you should start using JUnit 5 today


Faster Spring Boot startup

As software developers, we always look for opportunities to improve our efficiency at work and optimize repeatable activities. One of them is application startup. Even if you cover your production code with unit tests and follow TDD, from time to time checking how the whole application works is inevitable. The more often you run it, the more time is wasted on waiting until the application is ready to operate. Although the fast restart provided by Spring Boot DevTools is helpful for library class loading, it doesn’t solve the issue with the long startup of your own application code. From this post you will learn how to decrease the total number of coffee breaks in daily work by accelerating the startup of any Spring application in your local development environment.

Continue reading Faster Spring Boot startup


Accessing prototype bean in singleton

It’s not sheer coincidence or a random choice that the default scope in Spring is the singleton. The vast majority of business logic in our applications is placed in stateless objects, which thanks to the lack of state can be safely reused across the whole code base. However, sometimes some data needs to be stored between sequential calls to object’s methods. In that case we need to have more control over the life cycle of such object. Spring provides us with several scopes which live shorter than singletons and perfectly fit for short term data storage. The problem appears when you try to inject such scoped bean into a singleton. This post describes the possible options to access shorter living object inside these that reside in the container for longer periods. Although all examples will focus on a prototype inside a singleton, presented information applies to other scopes as well.

Continue reading Accessing prototype bean in singleton


Multiple TTL caches in Spring Boot

Spring Framework provides a comprehensive abstraction for common caching scenarios without coupling to any of supported cache implementations. However, declaration of expiration time for a particular storage is not a part of this abstraction. If we want to set Time To Live of a cache, the configuration of the chosen cache provider must be tuned. From this post you will learn how to prepare setup for several Caffeine caches with different TTL configurations.

Continue reading Multiple TTL caches in Spring Boot


Cross field validation

All built-in JSR 303 constraint annotations are intended to verify particular fields of our data classes. Yet, it is not unusual that several fields are connected to each other and should be checked as a unity. For instance, a field can be required only if another field is set. @NotNull won’t work in such case as there is no way to introduce the condition logic. In this post you will learn how to write a validator applicable to multiple class fields.

Continue reading Cross field validation


Custom parametrized validation annotation

In the previous post you could learn how to create a basic custom constraint annotation compatible with the Bean Validation standard. This demo will extend the former post by explaining how to create constraints which are more flexible due to parameters defined for particular use cases. If you’re totally unfamiliar with the topic, I refer you to the aforementioned post to grasp the essentials. Otherwise, just keep reading.

Continue reading Custom parametrized validation annotation


Custom validation annotation in Spring

Although built-in validation support in Spring is largely sufficient for standard use cases, sooner or later every developer runs into a situation when the sets of validation annotations provided by JSR 303 or Hibernate Validator are not enough. In this post you will learn how to create a simple constraint annotation served by a custom validator with access to the Spring context of a Spring Boot application.

Continue reading Custom validation annotation in Spring