Imagine you are creating a configuration class in Spring Boot that should only be processed if a certain bean is present in the ApplicationContext. How would you accomplish this?

  • Create a custom condition class implementing the Condition interface and specify the condition in the configuration class using @Conditional.
  • This behavior is not possible in Spring Boot; configuration classes are always processed regardless of the bean's presence.
  • Use the @ConditionalOnBean annotation on the configuration class and specify the required bean's class.
  • Use the @RequiresBean annotation and specify the required bean's name in the configuration class.
To conditionally process a configuration class based on the presence of a certain bean, you can use the @ConditionalOnBean annotation. This annotation ensures that the configuration class is only processed if the specified bean is present in the ApplicationContext. It's a powerful way to control the activation of configuration based on runtime conditions.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *