Introduction
As per spring-boot documentation, auto-configuration is implemented with standard @Configuration
classes. Additional @Conditional
annotations are used to constrain when the auto-configuration should apply. Usually, auto-configuration classes use @ConditionalOnClass
and @ConditionalOnMissingBean
annotations. This ensures that auto-configuration applies only when relevant classes are found and when you have not declared your own @Configuration
.
Spring introduced the @Conditional
annotation that allows users to define custom conditions to apply to parts of application context. Spring Boot builds on top of that and provides pre-defined conditions so we don’t need to implement them.
Spring-boot @Conditional
will allow flexibility to enable/disable modules or beans into the application context if the required conditions met.
Conditional Annotations
Spring Boot includes a number of @Conditional
annotations that we can reuse in our code by annotating @Configuration
classes or individual @Bean
methods. These annotations include:
- Class Conditions
- Bean Conditions
- Property Conditions
- Resource Conditions
- Web Application Conditions
- SpEL Expression Conditions
Please read reference spring-boot documentation of conditional annotations.
No comments :
Post a Comment