What does Spring Boot's auto-configuration do, and how do you change what it set up?
BackendMid-level
In shortBoot ships conditional configuration classes that create beans when a library is on the classpath and you haven't defined your own. Change it with properties and customizers; defining your own bean replaces the auto-configured one entirely.
Model answer
@SpringBootApplication includes @EnableAutoConfiguration, which loads the auto-configuration classes listed by every jar on the classpath. Each one is guarded by conditions:
@ConditionalOnClass: only if a library is present (Jackson, a JDBC driver, Redis).@ConditionalOnMissingBean: only if you haven’t defined that bean yourself.@ConditionalOnProperty: only if a setting is on.
So adding spring-boot-starter-web gives you Tomcat, Spring MVC and a configured JSON mapper without any code.
Changing it, from lightest to heaviest:
- Properties in
application.yml(server.port,spring.jackson.*). - Customizers, beans that adjust what Boot builds (
Jackson2ObjectMapperBuilderCustomizer,RestClientCustomizer). - Your own bean of the same type. The auto-configured one backs off completely, and its properties stop applying, which is a common surprise.
- Excluding an auto-configuration (
@SpringBootApplication(exclude = …)), rarely needed.
To see what happened and why, run with --debug for the conditions evaluation report, or call /actuator/conditions.
What they're looking for
Conditions (@ConditionalOnClass, @ConditionalOnMissingBean, @ConditionalOnProperty), the back-off rule, how to debug it (--debug, /actuator/conditions), and preferring properties or customizers over replacing beans.
Common mistakes
- Describing it as "magic" without the conditions behind it.
- Not knowing that your own bean switches off the auto-configured one, including its properties.
- Excluding whole auto-configurations to change one setting.
More backend questions
- What is the N+1 query problem, and how do you find and fix it?Mid-level
- How does a Spring backend authenticate requests from a mobile app, and how do you make sure users only see their own data?Mid-level
- Your Spring Boot service in Kubernetes keeps restarting with exit code 137. How do you investigate and fix it?Senior
- A Java service's p99 latency spikes every few minutes. How do you find the cause?Senior