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.
Loading...
Related Quiz
- The error messages of validation constraints in Spring Boot can be externalized using the _____ property in the constraint annotation.
- In a Spring Security application, you need to implement a feature where the users' passwords must be rotated every 30 days. How would you approach implementing this feature while maintaining a high level of security?
- To authorize access to method-level security in Spring Security, the _______ annotation can be used.
- How can you implement Token Enhancement to include additional information in the OAuth2 access token?
- To customize the way method parameters are bound to web requests in Spring Boot, you can use the @_____ annotation.