Java Developer interview question

How does Spring Boot auto-configuration work?

Spring Boot auto-configuration conditionally registers beans based on the classpath, properties, and existing beans; user-defined beans normally override defaults and the conditions report explains decisions.

Direct answer

What a strong answer covers

How it works

Auto-configuration is a set of @Configuration classes listed in the starter jars and loaded through the imports file. Each one is guarded by conditions: @ConditionalOnClass checks the classpath, @ConditionalOnProperty checks settings, @ConditionalOnMissingBean checks that the application has not already defined the bean. Because user configuration is processed first, defining your own DataSource or ObjectMapper replaces the default instead of duplicating it. The conditions evaluation report, printed with debug=true or through the actuator, lists every match and non-match with its reason.

Example

Adding spring-boot-starter-data-jpa and a datasource URL is enough to get a DataSource, an EntityManagerFactory, and transaction management with no explicit configuration. When a custom ObjectMapper bean unexpectedly disabled Spring Boot’s date handling, the conditions report showed JacksonAutoConfiguration backing off because a user bean was present, and the fix was a Jackson2ObjectMapperBuilderCustomizer instead of a replacement bean.

Common mistakes

  • Copying auto-configuration internals into your own config instead of customising through properties or customizers.
  • Adding starters that pull in unwanted behaviour such as security defaults and not noticing until deployment.
  • Debugging a missing bean by guessing rather than reading the conditions evaluation report.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
Java Developer interview questions