Java Academy · Lesson

Auto-Configuration and Spring Boot Starters

Understand how Spring Boot auto-configures beans based on classpath dependencies and condition annotations.

Lesson 1 of 413 steps

Auto-Configuration and Spring Boot Starters is a free Java Academy lesson on CoddyKit. This is lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, and your progress syncs across the web and the CoddyKit app. The Java Academy course includes 4 lessons in total.

What Is Spring Boot Auto-Configuration?

Auto-configuration automatically configures Spring beans based on what is present on the classpath and in the environment. It eliminates manual @Bean setup for common integrations.

The @SpringBootApplication Annotation

@SpringBootApplication is a composite of @Configuration, @EnableAutoConfiguration, and @ComponentScan. It activates auto-configuration and component scanning.

@SpringBootApplication
public class MyApp {
    public static void main(String[] args) {
        SpringApplication.run(MyApp.class, args);
    }
}

How Auto-Configuration Works

Spring Boot scans META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports (Spring Boot 3) for a list of auto-configuration classes. Each class is conditionally applied.

// Spring Boot 3 imports file:
// org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
// org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration

@ConditionalOnClass and @ConditionalOnMissingBean

Auto-configuration classes use @Conditional annotations to only apply when specific conditions are met — e.g., a class is on the classpath, or a bean has not already been defined.

@AutoConfiguration
@ConditionalOnClass(DataSource.class)
@ConditionalOnMissingBean(DataSource.class)
public class DataSourceAutoConfiguration {
    @Bean
    public DataSource dataSource(DataSourceProperties props) {
        return DataSourceBuilder.create().build();
    }
}

Spring Boot Starters

A starter is a curated set of dependency descriptors. Adding spring-boot-starter-web to your project brings in Spring MVC, Tomcat, Jackson, and their auto-configurations — no manual dependency hunting.

// build.gradle:
dependencies {
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"
    implementation "org.springframework.boot:spring-boot-starter-validation"
}

Common Starters

Key starters: starter-web (REST + Tomcat), starter-data-jpa (JPA + Hibernate), starter-security, starter-test (JUnit + Mockito), starter-actuator (health/metrics).

Overriding Auto-Configuration

Define your own @Bean of the same type to take precedence over auto-configured beans. @ConditionalOnMissingBean ensures the auto-configured bean is only created if yours is absent.

// Override auto-configured ObjectMapper:
@Configuration
public class JacksonConfig {
    @Bean
    public ObjectMapper objectMapper() {
        return new ObjectMapper()
            .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
            .registerModule(new JavaTimeModule());
    }
}

Excluding Auto-Configuration

Exclude specific auto-configuration classes you do not want — useful when a starter brings in something you want to configure manually.

@SpringBootApplication(exclude = {
    DataSourceAutoConfiguration.class,
    SecurityAutoConfiguration.class
})
public class MyApp { ... }

Creating Your Own Starter

Create a starter module with an auto-configuration class and register it in META-INF/spring/....AutoConfiguration.imports. Other projects that include your starter get your beans automatically.

// my-starter/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports:
// com.example.MyLibraryAutoConfiguration

Debugging Auto-Configuration

Run with --debug flag or set logging.level.org.springframework.boot.autoconfigure=DEBUG to see a "CONDITIONS EVALUATION REPORT" listing which auto-configurations were applied or excluded and why.

java -jar myapp.jar --debug
# Or in application.properties:
# logging.level.org.springframework.boot.autoconfigure=DEBUG

Actuator /conditions Endpoint

Enable spring-boot-starter-actuator and expose the /actuator/conditions endpoint to see the auto-configuration evaluation report at runtime without restarting.

# application.properties:
management.endpoints.web.exposure.include=conditions
# Then:
curl http://localhost:8080/actuator/conditions

Quick Check

What annotation causes a bean to be created only if no bean of that type is already defined?

Recap

Auto-configuration uses conditional annotations to wire beans based on classpath and existing beans. Starters bundle dependencies + auto-configuration. Override with your own beans. Exclude unwanted configurations. Debug with --debug.

Free to start

Learn Java with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
104
Lessons
374

Frequently Asked Questions

Is the “Auto-Configuration and Spring Boot Starters” lesson free?

Yes — the full text of “Auto-Configuration and Spring Boot Starters” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO. The Java Academy course includes 4 lessons in total.

What will I learn in “Auto-Configuration and Spring Boot Starters”?

Understand how Spring Boot auto-configures beans based on classpath dependencies and condition annotations. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 1 of 4.

How long does the “Auto-Configuration and Spring Boot Starters” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Auto-Configuration and Spring Boot Starters
  2. Application Properties and Profiles
  3. Bean Wiring: @Component, @Service, @Repository
  4. Constructor Injection and Circular Dependencies
← Back to Java Academy