Backend Development 7 min read

Understanding Spring Boot Auto‑Configuration Mechanism

This article explains how Spring Boot’s auto‑configuration works, covering the role of application properties, the @EnableAutoConfiguration annotation, condition annotations, the spring.factories mechanism, and how configuration properties are bound to beans such as ServerProperties to make settings like server.port effective.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Understanding Spring Boot Auto‑Configuration Mechanism

Spring Boot has become a must‑know skill for developers and interviewees, and its auto‑configuration feature is the core that simplifies setup by following the "convention over configuration" principle.

The global configuration file can be either application.properties or application.yml , where common keys such as server.port and logging.level.* are defined; these keys are documented in the official Spring Boot reference.

Auto‑configuration classes are packaged in spring-boot-autoconfigure‑x.x.x.x.jar . The @SpringBootApplication annotation includes @EnableAutoConfiguration , which triggers the import of auto‑configuration classes via AutoConfigurationImportSelector.selectImports() that reads META-INF/spring.factories from all jars on the classpath.

The spring.factories file lists entries where the key EnableAutoConfiguration maps to a comma‑separated list of xxxxAutoConfiguration class names; these classes are loaded into the Spring container during SpringApplication.run(...) .

Each auto‑configuration class is activated only when certain conditions are met, expressed by annotations such as @ConditionalOnBean , @ConditionalOnMissingBean , @ConditionalOnClass , @ConditionalOnMissingClass , and @ConditionalOnProperty .

Taking ServletWebServerFactoryAutoConfiguration as an example, the property server.port=8081 becomes effective because the class is annotated with @EnableConfigurationProperties(ServerProperties.class) . The @ConfigurationProperties annotation binds the values from the configuration file to a ServerProperties bean, which is then registered in the container.

In general, every xxxxAutoConfiguration class provides Java‑based bean definitions, while the corresponding xxxxProperties class holds the configuration values bound via @ConfigurationProperties . Understanding this flow helps answer interview questions concisely.

In summary, Spring Boot starts by locating all auto‑configuration classes through @EnableAutoConfiguration and the spring.factories file, loads them as JavaConfig, binds configuration properties to beans, and finally registers those beans in the application context.

backendJavaSpringSpring BootAnnotationsAuto‑Configurationconfiguration-properties
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.