How to use @ConditionalOnProperty annotation in Spring Boot?

Опубликовано: 28 Сентябрь 2024
на канале: Java Puzzle
1,600
25

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

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

Fortunately, achieving this isn't as hard as it might look upon first glance. The Spring framework provides the @ConditionalOnProperty annotation precisely for this purpose.

SOURCE CODE:
https://github.com/sawankarn/conditio...