How to Use and Test ConditionalOnProperty annotation in Spring Boot

The Bored Dev
4 min readJan 16, 2023

In this article we will learn how to test @ConditionalOnProperty annotation in Spring Boot. This annotation is specially useful for enabling or disabling components based on a feature flag.

Let’s start!

Introduction

The @ConditionalOnProperty annotation in Spring allows us to instantiate a component based a given condition. For example we could instantiate an implementation or another depending on a configuration property.

--

--