@ConditionalOnProperty tạo bean chỉ khi property có giá trị nhất định — feature flag, optional component.
java
@Component
@ConditionalOnProperty(name = "app.feature.email", havingValue = "true")
class EmailNotificationService implements NotificationService {}
@Component
@ConditionalOnMissingBean(CacheService.class) // fallback khi bean kia không được tạo
class InMemoryCacheService implements CacheService {}Set app.feature.email: true trong config → bean tồn tại; đổi false → biến mất, không sửa code. matchIfMissing = true → bean vẫn tạo khi property không được set.
Họ conditional khác: @ConditionalOnClass (class có trên classpath), @ConditionalOnMissingBean (user chưa define bean), @ConditionalOnWebApplication, @ConditionalOnExpression (SpEL).
Dùng nhiều trong: custom auto-configuration, feature toggle, optional integration (Redis có thì dùng, không thì in-memory).