1. Overview

In this short tutorial, we’re going to shed light on the main purpose of the @ConditionalOnProperty annotation.

First, we’ll start with a bit of background about what @ConditionalOnProperty is. Then, we’ll look at some practical examples to help understand how it works and what features it brings.

2. The Purpose of @ConditionalOnProperty

Typically, when developing Spring-based applications, we may need to create some beans conditionally based on the presence and the value of a configuration property.

For example, we may want to register a DataSource bean to point to a production or a test database depending on if we set a property value to “prod” or “test”.

#spring #spring boot

The Spring @ConditionalOnProperty Annotation
16.00 GEEK