You are tasked with creating a custom Auto Configuration that provides a set of beans only if a specific library is on the classpath. How would you approach this requirement?

  • Create the beans unconditionally, and Spring Boot will automatically handle the classpath check.
  • Include the library's JAR file directly in the project to guarantee its presence and enable the beans.
  • Use the @ConditionalOnClass annotation on the custom Auto Configuration class and specify the library's class in the annotation's value attribute. This ensures that the beans are created only if the specified class is on the classpath.
  • Use the @ConditionalOnProperty annotation with a condition that checks for the presence of the library's JAR file.
To create a custom Auto Configuration that provides beans conditionally based on the presence of a specific library on the classpath, you should use the @ConditionalOnClass annotation. Specify the library's class in the annotation's value attribute. This approach ensures that the beans are only created when the specified class is available on the classpath, ensuring the required conditions are met.
Add your answer
Loading...

Leave a comment

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