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 configuring faster Spring Boot startup in your local development environment.

Continue reading “Faster Spring Boot startup”

Why developers don’t use TDD

Although the total number of acronyms in the programing industry has probably already exceeded the number of stars observable on the moonless night sky, only a subset has gained popularity and recognition. TDD definitely belongs to this group. Judging by numerous conference lectures, books, podcasts, and blog posts, the fact that Test Driven Development is a widely known technique is rather undeniable. Yet, when you consider its adoption and actual usage the reality might look a bit different. In this article we will take a look at the different reasons for avoiding TDD that have been presented by candidates during several conducted technical interviews and try to disprove if they are real obstacles.

Continue reading “Why developers don’t use TDD”

Spring Cloud basic setup tutorial

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 tutorial”

Java project package structure guidelines

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 clarity.

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 for structuring Java packages.

So let’s get down to it.

Continue reading “Java project package structure guidelines”

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 in Spring and JEE

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 in Spring and JEE”

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”

Dual jar/war build for Spring Boot

The great thing about Spring Boot is no need for an external servlet container. All that is needed reside inside a single runnable JAR file. In a very few steps, development of a new application can be started without installation or configuration of any additional software.

Yet, sometimes you might want to deploy your application to some server as a regular WAR file. For instance, you convert an existing application and want to keep your continuous delivery pipe untouched or a particular container is enforced by a company’s policy. The reason for building a WAR file may vary across teams, but for development purpose a simple executable JAR file with an embedded server might be preferable.

Continue reading “Dual jar/war build for Spring Boot”