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.
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.
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.
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.
Some validation constraint can be applied to several different types. For instance the @Size annotation works with collections, arrays, and strings. This post is a guide on how to create a validation constraint which can be applied to different data types just like the aforementioned @Size 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.
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.
The Spring framework is the most widely adopted open source project in enterprise class applications. As the framework consists of dozens of modules, every team is interested only in a subset of changes introduces in the latest release. This post covers the list of new features that shouldn’t be missed by any developer whose application’s API relies on Spring 4 and is preparing for the upgrade in the foreseeable future.
Sending an e-mail from the backend application part is a quite common use case in the world of enterprise applications. Although HTML content isn’t standardized message format, numerous mail clients support at least a subset of the markup language. In this post you will learn how to send an e-mail using standard Spring Boot modules and prepare HTML content for a message using Thymeleaf template engine.
In the previous post you could read about separate Spring Boot builds for a local development machine and public environments. It’s highly possible that in addition to such setup you would like to load different Spring properties files based on the active Maven profile. In this note you will learn how to accomplish the desired result in a few easy steps.