SteelReed

Search

Search posts, questions…

Spring BootQuestion 8 / 26

Junior

What does @SpringBootApplication consist of? How is a starter different from auto-configuration?

Short answer

@SpringBootApplication combines @SpringBootConfiguration, @EnableAutoConfiguration and @ComponentScan. A starter just brings in compatible libraries; auto-configuration decides which beans to create based on the classpath.

on the classpathcreates beans@SpringBootApplication@SpringBootConfiguration@EnableAutoConfiguration@ComponentScanmain package downwardStarter: brings librariesDataSource, Tomcat...

3 points to say:

  1. @SpringBootApplication = configuration + auto-config + component scan.
  2. The starter brings libraries, auto-config creates beans; switch Tomcat to Jetty by swapping the starter.
  3. A misplaced main class is the most common "bean not found" cause, since scanning goes only from its package downward.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.