Spring Boot Auto-Configuration and Starters 4 — Questions and Answers
Question 1: Which meta-annotation is used to create a custom condition by implementing the Condition interface?
- @ConditionalOnCustom
- @Conditional (Correct answer)
- @EnableCondition
- @ConditionalOnBean
Correct answer: @Conditional
@Conditional(MyCondition.class) delegates the condition check to a custom class that implements the Condition interface's matches() method.
Question 2: What does the spring.autoconfigure.exclude property do when set in application.properties?
- Excludes packages from component scanning
- Prevents the listed auto-configuration classes from being loaded (Correct answer)
- Marks auto-configuration classes as deprecated
- Forces listed beans to be created lazily
Correct answer: Prevents the listed auto-configuration classes from being loaded
spring.autoconfigure.exclude accepts a comma-separated list of fully qualified auto-configuration class names to skip at startup.
Question 3: Which starter would you add to enable WebSocket support in a Spring Boot application?
- spring-boot-starter-websocket (Correct answer)
- spring-boot-starter-web-socket
- spring-boot-starter-messaging
- spring-boot-starter-stomp
Correct answer: spring-boot-starter-websocket
spring-boot-starter-websocket pulls in the Spring WebSocket library along with the necessary Spring MVC dependencies.
Question 4: When creating a custom Spring Boot starter, which module should contain the auto-configuration code according to Spring conventions?
- acme-spring-boot-starter
- acme-spring-boot-autoconfigure (Correct answer)
- acme-spring-boot-config
- acme-starter-core
Correct answer: acme-spring-boot-autoconfigure
Convention separates the autoconfigure module (with @AutoConfiguration classes) from the starter module (which is just a POM that depends on autoconfigure).
Question 5: Which condition annotation applies configuration only when the application is running inside a web application context?
- @ConditionalOnWebApplication (Correct answer)
- @ConditionalOnServlet
- @ConditionalOnMvc
- @ConditionalOnEmbeddedServer
Correct answer: @ConditionalOnWebApplication
@ConditionalOnWebApplication is true when the ApplicationContext is a servlet-based or reactive web application context.
Question 6: What is the role of spring-boot-autoconfigure JAR in relation to individual starters?
- It replaces all starters and must be added separately
- It contains the auto-configuration classes that starters activate when the right dependencies are present (Correct answer)
- It is only used by Spring Boot DevTools
- It provides starter POMs but no actual configuration code
Correct answer: It contains the auto-configuration classes that starters activate when the right dependencies are present
spring-boot-autoconfigure holds the auto-configuration classes for hundreds of integrations; starters pull it in along with the required libraries to trigger the relevant conditions.
Question 7: Which Spring Boot feature allows you to see a report of all auto-configuration evaluations and why each was applied or skipped?
- /actuator/beans endpoint
- The ConditionEvaluationReport, viewable via /actuator/conditions or DEBUG logging (Correct answer)
- spring.diagnostics.enabled=true property
- The @SpringBootTest(verbose=true) attribute
Correct answer: The ConditionEvaluationReport, viewable via /actuator/conditions or DEBUG logging
The ConditionEvaluationReport is exposed at /actuator/conditions (Actuator) or printed to console when DEBUG logging is enabled for Spring Boot.
Which meta-annotation is used to create a custom condition by implementing the Condition interface?