Spring Boot Auto-Configuration and Starters 3 — Questions and Answers
Question 1: Which annotation would you use to prevent a specific auto-configuration class from loading in tests?
- @DisableAutoConfiguration
- @SpringBootTest(excludeAutoConfiguration=…)
- @EnableAutoConfiguration(exclude=…) (Correct answer)
- @MockBean
Correct answer: @EnableAutoConfiguration(exclude=…)
@EnableAutoConfiguration(exclude={SomeAutoConfig.class}) and its spring.autoconfigure.exclude property both prevent named auto-configurations from loading.
Question 2: What does spring-boot-starter-actuator provide out of the box?
- A web UI for managing database schemas
- Production-ready endpoints for health, metrics, and application info (Correct answer)
- An embedded message broker
- Distributed tracing for microservices
Correct answer: Production-ready endpoints for health, metrics, and application info
spring-boot-starter-actuator adds Actuator endpoints such as /actuator/health, /actuator/metrics, and /actuator/info.
Question 3: When two auto-configuration classes need to be ordered relative to each other, which annotations can express that ordering?
- @Primary and @Secondary
- @AutoConfigureBefore and @AutoConfigureAfter (Correct answer)
- @Order and @Priority
- @DependsOn and @Lazy
Correct answer: @AutoConfigureBefore and @AutoConfigureAfter
@AutoConfigureBefore and @AutoConfigureAfter let auto-configurations declare ordering dependencies without requiring explicit bean wiring.
Question 4: Which condition annotation checks whether a specific Spring property has a particular value before applying a configuration?
- @ConditionalOnProperty (Correct answer)
- @ConditionalOnExpression
- @ConditionalOnEnvironment
- @ConditionalOnSetting
Correct answer: @ConditionalOnProperty
@ConditionalOnProperty(name='feature.enabled', havingValue='true') applies configuration only when the property matches the specified value.
Question 5: What is the difference between spring-boot-starter and spring-boot-starter-test?
- spring-boot-starter-test includes the full production stack; spring-boot-starter is for tests only
- spring-boot-starter provides core auto-configuration; spring-boot-starter-test adds JUnit, Mockito, and AssertJ scoped to test (Correct answer)
- They are identical; the names are interchangeable
- spring-boot-starter-test replaces spring-boot-starter in production
Correct answer: spring-boot-starter provides core auto-configuration; spring-boot-starter-test adds JUnit, Mockito, and AssertJ scoped to test
spring-boot-starter-test is a test-scoped starter bundling JUnit 5, Mockito, AssertJ, and Spring Test utilities, while spring-boot-starter provides core logging and auto-configuration.
Question 6: Which Spring Boot condition evaluates a SpEL expression to decide whether to apply a configuration?
- @ConditionalOnProperty
- @ConditionalOnExpression (Correct answer)
- @ConditionalOnSpEL
- @ConditionalOnBean
Correct answer: @ConditionalOnExpression
@ConditionalOnExpression accepts a SpEL string and applies the configuration only when the expression evaluates to true.
Question 7: Adding spring-boot-starter-cache to your project auto-configures which default cache provider when no other provider is detected?
- Redis
- Ehcache
- ConcurrentMapCache (simple in-memory) (Correct answer)
- Caffeine
Correct answer: ConcurrentMapCache (simple in-memory)
When no specific cache provider is on the classpath, Spring Boot defaults to a simple ConcurrentMapCache-backed CacheManager.
Which annotation would you use to prevent a specific auto-configuration class from loading in tests?