Kayavak / The Backend / BE·47 Spring Boot / Deeper
Deeper · The Backend
Spring Boot
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
By 2012 Spring had solved EJB's complexity and created its own: a new project meant choosing dozens of compatible library versions, writing XML or Java configuration for each, and deploying a WAR into a separately installed Tomcat. Ruby on Rails (2004) had shown the alternative, convention over configuration: sensible defaults, overridable when needed. Spring Boot 1.0 (April 2014) applied it to Spring: starters that pull in a tested set of dependencies, auto-configuration that sets up beans when it sees a library on the classpath, and an embedded server, so the application is just a JAR you run.
That last point matched where operations were going: containers and cloud platforms wanted self-contained processes with health endpoints and configuration from the environment, which Boot's Actuator and externalised configuration provided. Later versions added ahead-of-time processing and native images to reduce start-up time.
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
Spring Boot is Spring with opinions. On start-up it looks at what's on the classpath and in your configuration, and creates the beans you'd almost certainly have written yourself, stepping back wherever you define your own.
| Question | Answer |
|---|---|
| What is it? | A layer over Spring that auto-configures applications and packages them as runnable JARs |
| Problem it solves | Months of setup and version juggling reduced to a dependency and a main method |
| Parts | Starters, auto-configuration with conditions, externalised configuration, embedded server, Actuator, AOT, layered JARs |
| How it works | Conditional configuration classes create beans only if a class is present, a property is set, or no user bean exists |
| Assumptions | Defaults fit most applications; you override what doesn't |
| When they change | An unexpected library on the classpath switches on behaviour you didn't ask for |
| Where it fails | When nobody on the team knows what was configured; start-up cost of scanning and conditions |
| Related ideas | Spring Core (ch46); configuration and twelve-factor apps (Cloud, Production Deployment) |
What if?
What if you add a JDBC driver to the classpath with no database configured?
Reason it through, then open
Auto-configuration sees a data-source library and tries to create a DataSource, and with no URL it may fall back to
an embedded database if one is present or fail at start-up. That's the trade of convention over configuration:
behaviour follows from what's present. The --debug condition evaluation report shows exactly which auto-configurations
matched and why.
What if Boot had no "back off when the user defines a bean" rule?
Reason it through, then open
Every customisation would fight the defaults: two ObjectMappers, two security chains, ambiguous injection errors.
Most auto-configurations are guarded by "only if no bean of this type exists" (@ConditionalOnMissingBean), so
defining your own replaces the default cleanly. That rule is what makes the opinions overridable.
Where the boundary is
| Aspect | Spring Framework | Spring Boot |
|---|---|---|
| Provides | The container, DI, web, data, transactions | Defaults, starters, auto-configuration, packaging, operations endpoints |
| You configure | Everything explicitly | Only what differs from the defaults |
| Runs as | Whatever you build | A self-contained JAR by default |
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Spring Boot 1.0 was released in April 2014 | Historical | Spring's release announcement |
| Auto-configuration backs off for user-defined beans | Convention | Typically via @ConditionalOnMissingBean; not every auto-configuration does |
| Convention over configuration speeds up starting projects | Model | Widely experienced; costs appear later as hidden behaviour |
Still open
How much start-up time and memory Spring Boot applications can shed (AOT processing, native images, CRaC, Leyden) without losing Spring's flexibility is an ongoing effort.
What would change your mind? If your team routinely debugged surprising auto-configuration, explicit configuration might be cheaper for you. The condition report usually resolves that.
Recall
What does auto-configuration do?
Creates beans conditionally, based on the classpath, properties and which beans you've already defined.
How do you override a Boot default?
Define your own bean of that type; most auto-configurations back off.
How can you see which auto-configurations applied?
Run with --debug to print the condition evaluation report.
What idea did Boot borrow from Rails?
Convention over configuration.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.