With a small amount of work, you can speed up your application and improve the overall user experience. In this article, you will learn how to use the built-in HTTP response cache mechanism for Spring controller’s results.
Continue reading “HTTP cache with Spring examples”
Do you have multiple parameters annotated with @RequestParam in a request mapping method and feel it isn’t readable?
The annotation looks pretty straightforward when there’s one or two input parameters expected in a request but when the list gets longer you might feel overwhelmed.
You cannot use the @RequestParam annotation inside objects but it doesn’t mean you’re left with no other solution. In this post, I’m going to show you how to replace multiple @RequestParams with an object.
Continue reading “How to bind @RequestParam to object in Spring”
Whether you like it or not, software development is a collaborative activity. Integration work has always been demonized and treated as necessary evil. There are several approaches which try to solve the challenge of effective integration. The feature toggle belongs to that group. In this article, you’ll see in practice how feature toggles, also known as feature flags, can be used in your Spring Boot application.
Continue reading “Feature toggle in Spring Boot 2”
Sending an email 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 HTML email using Spring Boot standard modules and prepare an HTML content for a message using Thymeleaf template engine.
Continue reading “Sending HTML email with Spring Boot and Thymeleaf”
Although built-in validation support in Spring is largely sufficient for standard use cases, sooner or later you will run into a situation when the sets of validation annotations provided by JSR 303 or Hibernate Validator aren’t 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”
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”
The Spring framework with almost no effort can solve for you many common programming problems, but some of its features are less known than others. In this post, we’re going to take a close look at the @Lazy annotation, which belongs to this group. After reading several examples, you should be able to apply the annotation to your daily development tasks.
Continue reading “Spring @Lazy annotation use cases”
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”
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”
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”