Introduction to Spring & Spring Boot
Spring is the most widely used Java framework — an IoC container plus a vast ecosystem — and Spring Boot is the opinionated layer that makes spinning up a real, production-ready app fast and almost configuration-free.
Learn Introduction to Spring & Spring Boot in our free Java course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a…
Part of the free Java course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
Before You Start
This track assumes you understand dependency injection and interfaces , since Spring is fundamentally a DI container. Familiarity with annotations will make the syntax feel natural.
What You'll Learn
The Big Idea — A Kit Car vs a Car That Drives Off the Lot
💡 Analogy: Plain Spring is a superb engine you must bolt into a chassis yourself — powerful, but you wire the fuel lines, pick a server, and write the configuration. Spring Boot is the same engine delivered in a car that already starts: the wiring is done with sensible defaults, the server is built in, and you can drive away in minutes — yet you can still open the bonnet and change anything you like.
Boot does not hide Spring; it pre-assembles it. Underneath, the same IoC container is doing the work.
1️⃣ What Spring Is
At its core Spring is a dependency-injection container : you declare your objects as beans and Spring creates and wires them for you (Inversion of Control). Around that core is a large ecosystem — web (Spring MVC), data (Spring Data), security, messaging and more — all built on the same container.
2️⃣ A Spring Boot Application in One Class
Every Boot app has a class annotated with @SpringBootApplication and a main that calls SpringApplication.run(...) . That single line bootstraps the container, runs auto-configuration, and starts the embedded server.
3️⃣ Starters — Dependencies Made Simple
Rather than hand-picking compatible library versions, you add a starter — one coordinate that pulls in a curated bundle. spring-boot-starter-web brings Spring MVC, JSON support and an embedded Tomcat all at once.
4️⃣ What Happens on Startup
Understanding the startup sequence demystifies Boot: it is just creating the IoC container, scanning for your beans, applying conditional auto-configuration, and (for web apps) starting the server.
🧠 Quick Recall
Answer: No — Boot is a layer on top of Spring. It uses the same IoC container and adds auto-configuration, starters and an embedded server.
Answer: @Configuration , @EnableAutoConfiguration and @ComponentScan .
Answer: Boot embeds the server inside the runnable jar, so java -jar app.jar starts everything.
Common Misconceptions
- ❌ "Boot is a different framework." It is a layer on Spring using the same container. Fix: think of it as pre-assembled Spring.
- ❌ Putting the main class deep in a package. Component scanning starts from the main class's package. Fix: keep it at the root of your packages.
- ❌ Pinning every dependency version yourself. Starters and the BOM manage compatible versions. Fix: rely on starters.
- ❌ Fighting auto-configuration. It backs off when you define your own bean. Fix: override only what differs.
- ❌ Expecting a web server with no web starter. No web starter means no embedded server. Fix: add spring-boot-starter-web for REST.
Pro Tips
- 💡 Start every project at start.spring.io (Spring Initializr) to pick starters and generate the skeleton.
- 💡 Keep the main class at the package root so component scanning finds everything.
- 💡 Add Actuator early for free /health and /metrics endpoints in production.
- 💡 Lean on the defaults — only configure what genuinely differs from convention.
📋 Quick Reference
Concept
Syntax / idea
Note
app annotation
@SpringBootApplication
On the main class
launch
SpringApplication.run(...)
Boots the container
web starter
spring-boot-starter-web
MVC + JSON + Tomcat
data starter
spring-boot-starter-data-jpa
JPA + Hibernate
auto-config
@EnableAutoConfiguration
Defaults from classpath
component scan
@ComponentScan
Finds your beans
embedded server
Tomcat in the jar
java -jar app.jar
ops endpoints
Actuator
/health, /metrics
📚 Resources / Keep Learning
- 📘 Spring Boot Reference Documentation (docs.spring.io)
- 📗 Building an Application with Spring Boot — spring.io guide
- 📗 Spring Initializr — generate a new project
❓ Frequently Asked Questions
🎉 Lesson Complete!
You now know what the Spring Framework is, how Spring Boot layers auto-configuration, starters and an embedded server on top, and what @SpringBootApplication plus SpringApplication.run() do at startup.
Next up: Setting Up a Spring Boot Project — Spring Initializr, project structure, and your first runnable app.
Practice quiz
What is the Spring Framework, at its core?
- A build tool like Maven
- An IoC/dependency-injection container plus a large ecosystem of modules
- A web browser
- A relational database
Answer: An IoC/dependency-injection container plus a large ecosystem of modules. Spring's heart is its IoC container, which creates and wires beans; around it sits a huge ecosystem (web, data, security, etc.).
How does Spring Boot relate to the Spring Framework?
- It replaces Spring entirely
- It is an opinionated layer on top of Spring that adds auto-configuration and starters
- It is an unrelated language
- It only works without Spring
Answer: It is an opinionated layer on top of Spring that adds auto-configuration and starters. Spring Boot builds ON Spring, adding auto-configuration, starter dependencies, and an embedded server to remove boilerplate.
What problem does Spring Boot's 'auto-configuration' solve?
- It writes your business logic
- It configures sensible defaults based on the jars on the classpath
- It compiles Java to native code
- It encrypts the database
Answer: It configures sensible defaults based on the jars on the classpath. Auto-configuration inspects the classpath and existing beans, then wires reasonable defaults so you write far less setup code.
What is a 'starter' in Spring Boot?
- A main method
- A curated set of dependencies bundled under one coordinate (e.g. spring-boot-starter-web)
- A test runner
- A database driver only
Answer: A curated set of dependencies bundled under one coordinate (e.g. spring-boot-starter-web). A starter is a convenient dependency descriptor that pulls in a compatible group of libraries for a use case.
What does an 'embedded server' in Spring Boot mean?
- You must install Tomcat separately
- The servlet container (e.g. Tomcat) ships inside your runnable jar
- There is no web server
- It runs only in the cloud
Answer: The servlet container (e.g. Tomcat) ships inside your runnable jar. Spring Boot embeds a server like Tomcat so the app runs as a self-contained jar with java -jar, no external install.
Which is NOT a typical benefit Spring Boot advertises?
- Fast project bootstrapping
- Opinionated defaults
- Production-ready features like metrics and health checks
- Automatic generation of correct business requirements
Answer: Automatic generation of correct business requirements. Boot speeds setup and adds production tooling, but it cannot invent your domain logic or requirements for you.
The principle that an external container creates and wires your objects is called...
- Inversion of Control (IoC)
- Polymorphism
- Garbage collection
- Reflection
Answer: Inversion of Control (IoC). IoC means the framework controls object creation and wiring; dependency injection is how Spring implements IoC.
What is 'convention over configuration'?
- Forcing XML everywhere
- Providing sensible defaults so you only configure the exceptions
- Disabling all defaults
- Requiring manual wiring of every bean
Answer: Providing sensible defaults so you only configure the exceptions. Boot favours defaults: follow the conventions and you write almost no config, overriding only what differs.
Which module would you reach for to build REST web endpoints?
- spring-boot-starter-batch
- spring-boot-starter-web
- spring-boot-starter-mail
- spring-boot-starter-quartz
Answer: spring-boot-starter-web. spring-boot-starter-web bundles Spring MVC and an embedded server for building web and REST applications.
Spring Boot Actuator primarily provides...
- A GUI builder
- Production-ready endpoints such as /health and /metrics
- A new programming language
- Automatic UI styling
Answer: Production-ready endpoints such as /health and /metrics. Actuator exposes operational endpoints (health, metrics, info) to monitor and manage a running application.
Continue this course
- Previous: Final Project Ideas
- Next: Setting Up a Spring Boot Project