What is Spring Boot, and why does everyone use it?
Spring Boot is the Spring Framework with the setup already done. It makes opinionated guesses about how you want your application configured, gets out of the way when you disagree, and packages the result as a single runnable file.
The problem it solved
Spring itself has been around since 2003 and it is excellent. But by about 2012, starting a new Spring web application meant assembling this by hand:
- A
web.xmldeclaring theDispatcherServlet. - Several XML context files, or a stack of
@Configurationclasses. - A component-scan declaration.
- A view resolver, a message converter, a validator.
- A
DataSource, anEntityManagerFactory, a transaction manager. - Twenty-odd dependency versions that had to be mutually compatible.
- An external Tomcat to deploy the resulting WAR into.
None of that is your application. It is the same setup every project needs, retyped from memory or copied from the last project along with its bugs. A day or two of work before the first line of business logic.
<web-app>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
The Spring Boot equivalent of all of it:
@SpringBootApplication
public class BookstoreApplication {
public static void main(String[] args) {
SpringApplication.run(BookstoreApplication.class, args);
}
}
That starts an embedded Tomcat on port 8080, configures JSON serialisation, sets up error handling, scans your packages for components, and — if a database driver happens to be on the classpath — builds a connection pool and a transaction manager too.
Spring Boot is not a new framework. It is a layer on top of Spring that provides: opinionated starters (curated dependency sets), auto-configuration (conditional beans based on what is on your classpath), externalised configuration, an embedded server, and production-ready features such as health checks and metrics.
The four things Boot actually gives you
| Feature | What it replaces | Covered in |
|---|---|---|
| Starters | Hand-picking 25 compatible dependency versions | ch. 4 |
| Auto-configuration | Boilerplate @Bean definitions for infrastructure |
ch. 4 |
| Externalised config | Per-environment property plumbing and build-time filtering | ch. 5 |
| Embedded server + fat jar | Installing and managing an application server | ch. 14 |
| Actuator | Writing your own health check and metrics endpoints | ch. 12 |
Inversion of control, in plain terms
Everything Spring does rests on one idea. It is simple, but it is worth stating precisely because half of Spring's behaviour follows from it.
Normally, an object creates the things it needs:
public class BookService {
// This class decides which implementation it gets, and when.
private final BookRepository repository = new JdbcBookRepository(
new HikariDataSource(loadConfigFromSomewhere()));
public Book find(Long id) {
return repository.findById(id);
}
}
That compiles and runs, and it is painful: you cannot swap the repository in a test, the
service knows about connection pools, and every class that needs a DataSource
builds its own.
Inverting control means the object declares what it needs and someone else supplies it:
@Service
public class BookService {
private final BookRepository repository;
// "I need a BookRepository." Not which one, not how to build it.
public BookService(BookRepository repository) {
this.repository = repository;
}
public Book find(Long id) {
return repository.findById(id)
.orElseThrow(() -> new BookNotFoundException(id));
}
}
The "someone else" is the Spring container — an object that knows how to build every component in your application and wire them together. Supplying the dependency is dependency injection; the container doing the deciding is inversion of control. Same idea, two names.
In a test, new BookService(mockRepository) works with no Spring involved at
all. That is the practical payoff, and it is why constructor injection is the only style
this course recommends.
How Spring Boot is put together
| Piece | What it does |
|---|---|
SpringApplication.run() |
Creates the ApplicationContext, runs the whole startup sequence, and returns once the app is ready. |
ApplicationContext |
The container. Holds every bean, manages their lifecycle, publishes events, resolves properties. |
Environment |
All configuration, merged from files, environment variables and command line, in a fixed precedence order. |
| Auto-configuration classes | ~150 conditional @Configuration classes that register infrastructure beans if — and only if — they are needed. |
| AOP proxies | Wrappers created around your beans so @Transactional, @Async, @Cacheable and friends can intercept calls. |
| Embedded server | Tomcat by default; Jetty, Undertow or a reactive Netty server if you swap the starter. |
What happens when you run main()
- BootstrapBoot works out the application type (servlet, reactive, or none) from what is on the classpath.
- Environment preparedProperty sources are loaded and ordered; active profiles are resolved.
- Context createdAn
AnnotationConfigServletWebServerApplicationContext, usually. - Bean definitions registeredComponent scanning finds your
@Components; the auto-configuration selector adds its candidates. - Conditions evaluatedEach auto-configuration is kept or discarded based on its
@Conditional…annotations. - Singletons instantiatedBeans are created in dependency order, initialised, and wrapped in proxies where needed.
- Web server startedTomcat binds the port and starts accepting requests.
- Runners execute
ApplicationRunnerandCommandLineRunnerbeans run, thenApplicationReadyEventis published.
Spring vs Spring Boot vs Spring Cloud
These three names get used interchangeably and they should not be.
| Spring Framework | Spring Boot | Spring Cloud | |
|---|---|---|---|
| What it is | The core container, MVC, AOP, transactions | Opinionated setup on top of Spring | Distributed-systems patterns on top of Boot |
| Gives you | DI, @Transactional, DispatcherServlet | Starters, auto-config, embedded server | Config server, service discovery, gateway, resilience |
| Can you use it alone? | Yes, but you configure everything | Yes — this is the normal choice | No, it requires Boot |
| Do you need it? | Always (Boot includes it) | Almost always | Only for multi-service architectures |
@Component, @Service, @Autowired,
@Transactional, @RestController and @GetMapping all
come from the Spring Framework, not Boot. Boot's own contributions are a
short list: @SpringBootApplication, @EnableAutoConfiguration,
@ConfigurationProperties, @ConditionalOn… and the test
annotations. Knowing the split makes documentation far easier to navigate.
When Spring Boot is the wrong choice
It is not the answer to every JVM problem:
- A CLI tool or short-lived job. Startup cost and memory footprint dominate. Picocli, or Quarkus/native if you need Spring-like structure.
- An AWS Lambda with strict cold-start limits. Possible with native images or SnapStart, but you are fighting the runtime model.
- A tiny library. Do not force consumers to adopt your container.
- Hard real-time or very low memory environments. The container costs tens of megabytes before your code exists.
For a long-running HTTP or messaging service — which is most backend work — it is close to the default correct answer, and the ecosystem is the real reason: security, data access, messaging, batch, observability and testing are all designed to fit together.
The mental model to carry forward
- A Spring application is a bag of objects the container built and wired for you.
- Auto-configuration is conditional bean definitions — nothing more mysterious than that.
- Most annotations work by wrapping your bean in a proxy, which explains most of their surprising edge cases.
Hold those three and the remaining fifteen chapters are details.
Which statement about Spring Boot is false?
Boot is a layer on top of the Spring Framework, using exactly the same container and the same DI mechanism. It adds starters, auto-configuration, externalised configuration and the embedded server — it replaces none of the core.
What is next
Chapter 2 generates a project, dissects @SpringBootApplication annotation by
annotation, and gets a working REST endpoint running — with a proper look at what the
startup log is telling you.