Spring Boot Overview
Definition
Spring Boot is Spring with sensible defaults. It sets things up for you based on what is on the classpath, bundles an embedded server, and adds production features like health checks, so one main class starts a working application.
Why it exists
Early Spring needed long XML files, version juggling and an external server just to get started. Boot removes that setup so you begin with working code.
How it works
What Boot gives you
| Problem in plain Spring | What Boot does | Page |
|---|---|---|
| Hundreds of compatible library versions to pick | Curated dependency management and starters | Starters |
Manual DataSource, ObjectMapper, DispatcherServlet setup | Auto-configuration that backs off when you define your own | Auto-configuration |
Scattered .properties and environment handling | Externalized configuration with type-safe binding | Configuration |
| Separate WAR and app server | Embedded Tomcat/Jetty/Undertow and executable JAR | this page |
| No visibility in production | Actuator endpoints | Actuator |
What happens at startup
@SpringBootApplication is a shortcut for three annotations:
@SpringBootConfiguration: this class is a@Configuration.@EnableAutoConfiguration: turn on auto-configuration.@ComponentScan: scan the current package and its sub-packages for components.
@SpringBootApplication
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class, args);
}
}
SpringApplication.run does roughly this:
Because the web server starts as part of refresh(), a Boot app is just a Java program with a server inside it, which is why it containerises so easily.
System design considerations
- Pin a Boot version through the BOM and upgrade on a schedule
- Externalise configuration for each environment, not inside the jar
- Expose health and metrics endpoints so the platform can manage the service
When to use it, and when not
Use it when
- You build a new Java service or REST API
- You want production features (health, metrics) without assembling them
- You deploy as a container or executable jar
Think twice when
- You need a tiny footprint where startup and memory are critical and a lighter framework fits
- The platform mandates an external application server
- You are unwilling to follow its conventions and would fight them
Common mistakes
- Putting the main class in the default package, or in a package that does not contain your components, so scanning misses them.
- Treating Boot as magic. When something is wired unexpectedly, run with
--debugto see the auto-configuration report (see Auto-configuration). - Running heavy logic inside
CommandLineRunnerand delaying readiness. Prefer readiness probes (see Actuator).
Interview questions
1. What is the difference between Spring and Spring Boot?
Spring is the framework: IoC container, AOP, data access, MVC. Boot is a set of conventions on top of it: starters, auto-configuration, embedded servers, Actuator and externalized config. You can use Spring without Boot, but you cannot use Boot without Spring.
2. What does @SpringBootApplication do?
It combines @SpringBootConfiguration, @EnableAutoConfiguration and @ComponentScan. Component scanning starts at the package of the annotated class, so put the main class in the root package of your app.
3. How does Boot run without an external Tomcat?
The spring-boot-starter-web dependency brings an embedded Tomcat. A ServletWebServerFactory bean (auto-configured) creates and starts it during context refresh. The Maven/Gradle plugin repackages the app into a "fat JAR" whose launcher loads nested dependency JARs.
4. How do you change the embedded server?
Exclude spring-boot-starter-tomcat from the web starter and add spring-boot-starter-jetty (or undertow). Auto-configuration picks whichever is on the classpath.
5. What is the difference between CommandLineRunner and ApplicationRunner?
Both run after the context is ready. CommandLineRunner receives raw String... args; ApplicationRunner receives a parsed ApplicationArguments (options such as --flag=value vs plain arguments).
Check yourself
1What is Spring Boot mainly responsible for?
2What does @SpringBootApplication combine?
3How is a Boot web app usually started?
Key takeaways
- Boot is Spring plus defaults: starters, auto-configuration, embedded server, Actuator.
@SpringBootApplication= configuration + auto-configuration + component scan.- Everything happens inside
SpringApplication.run: environment, context, bean creation, server start, runners. - Your own beans always take priority over auto-configured ones.
Finished this page? Track your progress (saved only in your browser).