Introduction to Spring Boot
Servlet containers, Spring MVC, IoC, Dispatcher Servlet, and Spring Boot's three core advantages
- Trace the evolution from Servlets to Spring MVC to Spring Boot
- Explain embedded server, auto-configuration, and opinionated defaults
- Understand the Dispatcher Servlet request flow
Topics Covered:
Servlets & Servlet Containers · web.xml · Spring Framework & Spring MVC · Inversion of Control (IoC) & Dependency Injection · Dispatcher Servlet · Spring Boot's Three Core Advantages · Embedded Server · Auto Configuration · Dependency Management · Convention over Configuration
Overview
To understand why Spring Boot exists, you must first understand the problems that existed before it. The evolution goes through three distinct stages:
1Servlets → Spring MVC (Spring Framework) → Spring BootEach stage solved the problems of the previous one. Spring Boot is not a replacement for Spring MVC — it is built on top of it, adding automation and simplification while keeping all existing Spring MVC features intact.
Stage 1 Servlets and Servlet Containers
What Is a Servlet?
Servlet:
A Java class that handles an HTTP client request, processes it, and sends back an HTTP response.
Think of a Servlet as your earliest form of a controller — it receives an incoming API call, does some work, and returns a result.
Servlet Syntax
1@WebServlet("/demo-servlet-one")2public class DemoServletOne extends HttpServlet {3
4 @Override5 protected void doGet(HttpServletRequest request, HttpServletResponse response)6 throws ServletException, IOException {7
8 String path = request.getRequestURI();9
10 if (path.contains("/first-endpoint")) {11 // process request for /first-endpoint12 response.getWriter().write("Response from first endpoint");13
14 } else if (path.contains("/second-endpoint")) {15 // process request for /second-endpoint16 response.getWriter().write("Response from second endpoint");17 }18 }19
20 @Override21 protected void doPost(HttpServletRequest request, HttpServletResponse response)22 throws ServletException, IOException {23 // handle POST requests24 }25
26 @Override27 protected void doPut(HttpServletRequest request, HttpServletResponse response)28 throws ServletException, IOException {29 // handle PUT requests30 }31}1@WebServlet("/demo-servlet-two")2public class DemoServletTwo extends HttpServlet {3
4 @Override5 protected void doGet(HttpServletRequest request, HttpServletResponse response)6 throws ServletException, IOException {7 // handle GET for servlet two8 }9}Servlet Breakdown
| Element | Explanation |
|---|---|
extends HttpServlet | Every servlet must extend this base class |
@WebServlet("/path") | Annotation to map a URL path to this servlet |
doGet() | Handles HTTP GET requests |
doPost() | Handles HTTP POST requests |
doPut() | Handles HTTP PUT requests |
doDelete() | Handles HTTP DELETE requests |
HttpServletRequest | Carries all incoming request data (path, parameters, body, headers) |
HttpServletResponse | Used to write the response back to the client |
doGet(), one doPost(), one doPut(), and one doDelete() method. This means all path-based routing within a servlet must be done manually with if-else if chains — a major limitation.What Is a Servlet Container?
Servlet Container:
A runtime environment (like Apache Tomcat) that manages the lifecycle of servlets — creating, invoking, and destroying them as needed.
The servlet container is responsible for:
- Receiving incoming HTTP requests.
- Consulting
web.xmlto determine which servlet handles the request. - Invoking the appropriate servlet method.
- Returning the servlet's response to the client.
Tomcat is the most well-known servlet container. It is also commonly called an application server.
The `web.xml` Servlet Mapping Configuration
In the servlet era, all URL-to-servlet mappings were defined in a file called web.xml. This file lived in the WEB-INF directory of the application.
Example `web.xml`
1<web-app>2
3 <!-- Declare Servlet One -->4 <servlet>5 <servlet-name>DemoServletOne</servlet-name>6 <servlet-class>com.example.DemoServletOne</servlet-class>7 </servlet>8
9 <!-- Map URL patterns to Servlet One -->10 <servlet-mapping>11 <servlet-name>DemoServletOne</servlet-name>12 <url-pattern>/demo-servlet-one/*</url-pattern>13 </servlet-mapping>14
15 <!-- Declare Servlet Two -->16 <servlet>17 <servlet-name>DemoServletTwo</servlet-name>18 <servlet-class>com.example.DemoServletTwo</servlet-class>19 </servlet>20
21 <!-- Map URL patterns to Servlet Two -->22 <servlet-mapping>23 <servlet-name>DemoServletTwo</servlet-name>24 <url-pattern>/demo-servlet-two/*</url-pattern>25 </servlet-mapping>26
27</web-app>How a Request Was Routed (Servlet Era)
The Deployment Process (Servlet Era)
1Developer writes code2 ↓3Packages application into a WAR file4 ↓5Manually deploys WAR to Tomcat6 ↓7Tomcat reads web.xml and serves requestsProblems With Servlets
1. `web.xml` Becomes Unmanageable
In a production application with hundreds of servlets, the web.xml becomes enormous — containing servlet declarations, mappings, filter chains, security configurations, and more. It becomes extremely difficult to read and maintain.
2. Tight Coupling No Dependency Injection
In servlets, objects are created manually with new. This leads to tight coupling between classes, making unit testing extremely difficult.
1// Tight coupling — cannot mock UserService in unit tests2public class PaymentServlet extends HttpServlet {3 private UserService userService = new UserService(); // hard-coded dependency4
5 protected void doGet(HttpServletRequest req, HttpServletResponse res) {6 // If you want to unit test this, you CANNOT mock userService7 // because it's hard-coded with 'new'8 String details = userService.getUserDetail(req.getParameter("id"));9 }10}If you want to unit test doGet() in isolation, you cannot replace userService with a mock because it is instantiated directly inside the class. You always get the real UserService, which may call a real database.
3. Rigid Request Routing
Each servlet can only have one of each HTTP method handler (doGet, doPost, etc.). If ten different GET endpoints need to be served by related logic, they must all squeeze into one doGet() method with sprawling if-else if chains — hard to read and maintain.
4. Manual WAR Deployment
Every time you want to run or update the application, you must build a WAR file and manually deploy it to an external Tomcat server. This slows down development.
Stage 2 Spring Framework (Spring MVC)
What Spring MVC Solved
Spring Framework — specifically the Spring MVC module — was introduced to address all of the servlet problems above. It is built on top of servlets internally, but provides a much cleaner programming model.
Advantage 1 Removal of `web.xml` (Annotation-Based Configuration)
Spring MVC replaces web.xml mappings with Java annotations directly on controller classes and methods.
1@Controller2@RequestMapping("/payment")3public class PaymentController {4
5 @GetMapping("/details")6 public String getPaymentDetails() {7 return "payment details";8 }9
10 @PostMapping("/process")11 public String processPayment() {12 return "payment processed";13 }14
15 @GetMapping("/history")16 public String getHistory() {17 return "payment history";18 }19}Instead of one doGet() with if-else if blocks, you now have one method per endpoint, each cleanly annotated. Ten GET endpoints = ten @GetMapping methods. No web.xml required.
Advantage 2 Inversion of Control (IoC) and Dependency Injection (DI)
What Is Inversion of Control?
Inversion of Control (IoC):
A design principle in which the control of object creation and lifecycle management is transferred from the developer's code to a framework (in this case, the Spring container).
Dependency Injection (DI):
The primary implementation mechanism of IoC. Instead of a class creating its own dependencies using new, the framework creates and injects those dependencies automatically.
The Problem Tight Coupling (Without DI)
1// Without Dependency Injection2public class PaymentService {3 // Hard-coded dependency — tight coupling4 private UserService userService = new UserService();5
6 public String getSenderDetails(String id) {7 return userService.getUserDetail(id);8 }9}Why this is a problem:
- To unit test
getSenderDetails(), you want to test only that method's logic. - You want to mock
UserService— tell it "whenevergetUserDetail()is called, return this fake value." - But because
UserServiceis created withnewinside the class, Spring (or any test framework) cannot replace it with a mock. You always get the realUserService. - Result: unit testing is nearly impossible without calling real dependencies (databases, services, etc.).
The Solution Dependency Injection With Spring
1// With Dependency Injection2@Component3public class UserService {4 public String getUserDetail(String id) {5 return "User: " + id;6 }7}8
9@Component10public class PaymentService {11
12 @Autowired13 private UserService userService; // Spring injects this — not 'new'14
15 public String getSenderDetails(String id) {16 return userService.getUserDetail(id);17 }18}How It Works
| Annotation | Purpose |
|---|---|
@Component | Marks a class as a Spring-managed bean. Spring will create and manage its lifecycle. |
@Autowired | Tells Spring to inject the required dependency automatically when the class is instantiated. |
With @Autowired, Spring manages the UserService object. In a unit test, you can provide a mock UserService to Spring, and Spring will inject that mock instead of the real one. Your test is now fully isolated.
1// In a unit test (using Mockito)2@Mock3UserService mockUserService;4
5@InjectMocks6PaymentService paymentService;7
8// Tell the mock: when getUserDetail("123") is called, return "Fake User"9when(mockUserService.getUserDetail("123")).thenReturn("Fake User");10
11// Now test PaymentService in isolation12String result = paymentService.getSenderDetails("123");13assertEquals("Fake User", result);Advantage 3 Organized REST API Handling (Dispatcher Servlet)
Spring MVC introduces the Dispatcher Servlet — a single, centralized servlet that receives all incoming requests and routes them to the correct controller and method.
Dispatcher Servlet:
Also known as the Front Controller. It is the single entry point for all HTTP requests in a Spring MVC application. It uses handler mappings (the annotations on controllers) to determine which controller class and which method to invoke.
How a Request Is Routed in Spring MVC
Step-by-Step Execution
- Client sends
GET /payment/details. - Tomcat receives it and passes it to the Dispatcher Servlet.
- Dispatcher Servlet consults Handler Mapping — looks at all
@RequestMapping,@GetMapping, etc. annotations to find which controller and method matches/payment/details. - Dispatcher Servlet asks the IoC container to create an instance of
PaymentControllerand resolve all its@Autowireddependencies. - Dispatcher Servlet invokes
getPaymentDetails()on the created instance. - The method processes the request and returns a response.
- Response travels back through Dispatcher Servlet → Tomcat → Client.
Advantage 4 Rich Ecosystem Integrations
Spring Framework provides ready-made integrations with almost every major Java technology:
| Category | Integration Options |
|---|---|
| Unit Testing | JUnit, Mockito |
| Database ORM | Hibernate, JPA |
| Database JDBC | Spring JDBC |
| Caching | EhCache, Redis |
| Messaging | RabbitMQ, Kafka |
| Security | Spring Security |
| Async Programming | Spring Async, @Async |
A Spring MVC Application Required Boilerplate
Even with all the improvements over servlets, a minimal Spring MVC application still required four components:
1. Controller Class
1@Controller2@RequestMapping("/my-api")3public class MyController {4
5 @GetMapping("/first-api")6 public @ResponseBody String firstApi() {7 return "Hello from Spring MVC";8 }9}2. `pom.xml` With Explicit Versions
1<dependencies>2
3 <!-- Spring MVC -->4 <dependency>5 <groupId>org.springframework</groupId>6 <artifactId>spring-webmvc</artifactId>7 <version>5.3.20</version> <!-- Must specify version manually -->8 </dependency>9
10 <!-- Servlet API -->11 <dependency>12 <groupId>javax.servlet</groupId>13 <artifactId>javax.servlet-api</artifactId>14 <version>4.0.1</version> <!-- Must specify version manually -->15 </dependency>16
17 <!-- JUnit for testing -->18 <dependency>19 <groupId>junit</groupId>20 <artifactId>junit</artifactId>21 <version>4.13.2</version> <!-- Must specify version manually -->22 </dependency>23
24</dependencies>3. Application Configuration Class
1@Configuration2@EnableWebMvc3@ComponentScan(basePackages = "com.example")4public class AppConfig {5 // Loads Spring MVC configuration6 // Defines component scanning scope7}4. Dispatcher Servlet Registration Class
1public class MyDispatcherServlet extends AbstractAnnotationConfigDispatcherServletInitializer {2
3 @Override4 protected Class<?>[] getRootConfigClasses() {5 return null;6 }7
8 @Override9 protected Class<?>[] getServletConfigClasses() {10 return new Class[]{AppConfig.class}; // link to config class11 }12
13 @Override14 protected String[] getServletMappings() {15 return new String[]{"/"}; // handle all requests16 }17}Problems That Remain With Spring MVC
| Problem | Detail |
|---|---|
| Dependency Management | Every dependency must be added manually with an exact version. Versions across multiple dependencies must be manually kept compatible with each other. |
| Manual Configuration | AppConfig class with @EnableWebMvc, @ComponentScan, and the DispatcherServlet registration class must all be written by hand for every project. |
| External Deployment | Application must still be packaged as a WAR and deployed to an external Tomcat server. |
Stage 3 Spring Boot
What Spring Boot Solves
Spring Boot
provides a quick way to create production-ready Spring applications. It is built on top of Spring MVC and inherits all of its features, while adding automation to eliminate boilerplate.
Spring Boot's philosophy is called Convention over Configuration (also called opinionated defaults):
- Spring Boot makes sensible default choices for you.
- If you agree with the defaults, you write zero configuration.
- If you disagree, you can override any default with your own configuration.
Spring Boot solves the three remaining Spring MVC problems with three specific advantages.
Spring Boot Advantage 1 Dependency Management
The Spring MVC Problem
In Spring MVC, you must:
- Manually add every dependency you need.
- Manually specify the version for each dependency.
- Manually ensure all versions are compatible with each other.
If you upgrade JUnit from 4.13.2 to 5.1.0, will it still work with your current Spring version? You have to research and verify this yourself.
The Spring Boot Solution Starters and Parent POM
Spring Boot introduces starter dependencies — curated bundles that pull in all required transitive dependencies for a feature, with pre-verified compatible versions.
1<!-- Spring Boot pom.xml -->2<parent>3 <groupId>org.springframework.boot</groupId>4 <artifactId>spring-boot-starter-parent</artifactId>5 <version>3.1.0</version> <!-- Only ONE version to define -->6</parent>7
8<dependencies>9
10 <!-- Everything needed for a web app — one line -->11 <dependency>12 <groupId>org.springframework.boot</groupId>13 <artifactId>spring-boot-starter-web</artifactId>14 <!-- No version needed! Parent manages it -->15 </dependency>16
17 <!-- Everything needed for testing — one line -->18 <dependency>19 <groupId>org.springframework.boot</groupId>20 <artifactId>spring-boot-starter-test</artifactId>21 <!-- No version needed! -->22 </dependency>23
24</dependencies>Compare:
| Spring MVC | Spring Boot | |
|---|---|---|
| Dependencies to add | Each individually (15–20 for a web app) | 1–2 starters |
| Versions to specify | Every single one | Only the Spring Boot parent version |
| Compatibility check | Manual | Automatic (guaranteed by Spring Boot team) |
spring-boot-starter-web internally pulls in Spring MVC, embedded Tomcat, Jackson (for JSON), validation libraries, logging, and more — all with compatible versions. You write one line; Spring Boot handles everything else.Spring Boot Advantage 2 Auto Configuration
The Spring MVC Problem
Every Spring MVC project requires manually writing:
AppConfig.javawith@Configuration,@EnableWebMvc,@ComponentScanDispatcherServletInitializer.javato register the dispatcher servlet- Explicit component scan base package
The Spring Boot Solution `@SpringBootApplication`
Spring Boot replaces all of that with a single annotation on the main application class.
1@SpringBootApplication // This one annotation does it all2public class MyApplication {3
4 public static void main(String[] args) {5 SpringApplication.run(MyApplication.class, args);6 }7}@SpringBootApplication is a composed annotation that internally contains:
1@SpringBootApplication2├── @EnableAutoConfiguration → triggers auto-configuration mechanism3├── @ComponentScan → scans current package and sub-packages4└── @SpringBootConfiguration → marks this as a configuration class (includes @EnableWebMvc)| What Spring MVC Needs | What Spring Boot Does Instead |
|---|---|
Explicit @EnableWebMvc | Auto-configured internally |
Explicit @ComponentScan(basePackages = "...") | Auto-scans from the package of your main class downward |
Manual DispatcherServlet registration class | Registered automatically |
Manual AppConfig class | Not needed |
Opinionated Default Component Scan
Spring Boot's opinion: "Start scanning from the package where your main method lives, and scan all sub-packages."
If you agree with this (which works for most projects), you write nothing. If you need a different base package, you can override it:
1@SpringBootApplication2@ComponentScan(basePackages = "com.different.package") // override the default3public class MyApplication {4 public static void main(String[] args) {5 SpringApplication.run(MyApplication.class, args);6 }7}Spring Boot Advantage 3 Embedded Server
The Problem With Servlet and Spring MVC
In both the Servlet era and Spring MVC, the deployment process was:
1Write code2 ↓3Package into WAR file4 ↓5Install and configure external Tomcat6 ↓7Deploy WAR to Tomcat8 ↓9Start Tomcat10 ↓11Application is runningThis is slow for development, requires Tomcat to be separately installed and managed, and introduces environment inconsistency (the Tomcat version on your laptop vs the server might differ).
The Spring Boot Solution Embedded Tomcat
Spring Boot embeds Tomcat directly inside the application JAR. You do not need to install or configure any external server. You simply run the application like any other Java program.
1Write code2 ↓3Run main() method (or java -jar myapp.jar)4 ↓5Application is running (Tomcat starts automatically inside the process)What the Console Looks Like
1 . ____ _ __ _ _2 /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \3( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \4 \\/ ___)| |_)| | | | | || (_| | ) ) ) )5 ' |____| .__|_| |_|_| |_\__, | / / / /6 =========|_|==============|___/=/_/_/_/7 :: Spring Boot :: (v3.1.0)8
9...10Tomcat started on port(s): 8080 (http) ← Embedded Tomcat starts automatically11Started MyApplication in 2.345 secondsTomcat is started automatically as part of your application. You can immediately hit http://localhost:8080/my-api/first-api in a browser.
A Complete Spring Boot Application Minimal Code
`pom.xml`
1<parent>2 <groupId>org.springframework.boot</groupId>3 <artifactId>spring-boot-starter-parent</artifactId>4 <version>3.1.0</version>5</parent>6
7<dependencies>8 <dependency>9 <groupId>org.springframework.boot</groupId>10 <artifactId>spring-boot-starter-web</artifactId>11 </dependency>12</dependencies>Main Application Class
1@SpringBootApplication2public class MyApplication {3 public static void main(String[] args) {4 SpringApplication.run(MyApplication.class, args);5 }6}Controller Class
1@RestController2@RequestMapping("/my-api")3public class MyController {4
5 @GetMapping("/first-api")6 public String firstApi() {7 return "Hello from Spring Boot!";8 }9}Output in Browser
Hit http://localhost:8080/my-api/first-api:
1Hello from Spring Boot!Three files. No web.xml. No AppConfig. No DispatcherServletInitializer. No WAR. No external Tomcat.
Compare this to the four required files in Spring MVC and the web.xml mapping in the Servlet era.
How Spring Boot Still Uses Dispatcher Servlet Internally
Spring Boot does not remove the Dispatcher Servlet — it just configures it automatically so you never have to write the setup code yourself.
Everything that happened in Spring MVC still happens — it is just automated and hidden inside the @SpringBootApplication annotation and the spring-boot-starter-web dependency.
Full Evolution Diagram
Comparison Table All Three Stages
| Feature | Servlet | Spring MVC | Spring Boot |
|---|---|---|---|
| URL Mapping | web.xml | Annotations (@GetMapping) | Annotations (same) |
| Dependency Injection | None (manual new) | @Autowired, @Component | Same (auto-configured) |
| Configuration | web.xml (XML) | Java config classes | Auto-configured via @SpringBootApplication |
| Dispatcher Servlet | None (manual routing) | Manual setup required | Auto-configured |
| Dependency Management | Manual | Manual with versions | Starters, no versions needed |
| Server | External Tomcat (WAR) | External Tomcat (WAR) | Embedded Tomcat (JAR) |
| Unit Testability | Hard | Easy (Mockito, JUnit) | Easy (same) |
| Boilerplate Code | High | Medium | Minimal |
| Production Readiness | Manual | Manual | Built-in metrics, health checks |
Key Definitions Recap
| Term | Definition |
|---|---|
| Servlet | A Java class that handles HTTP requests and responses |
| Servlet Container | Runtime (e.g., Tomcat) that manages servlet lifecycle |
web.xml | XML file mapping URLs to servlet classes (pre-Spring) |
| IoC (Inversion of Control) | Framework manages object creation and lifecycle instead of the developer |
| Dependency Injection | Spring injects object dependencies automatically via @Autowired |
@Component | Marks a class for Spring to manage as a bean |
@Autowired | Tells Spring to inject the required dependency |
| Dispatcher Servlet | Spring's front controller — routes all requests to the correct controller/method |
| Handler Mapping | The mechanism (via @RequestMapping, @GetMapping, etc.) that tells Dispatcher Servlet which controller and method to call |
@SpringBootApplication | Composed annotation combining @EnableAutoConfiguration, @ComponentScan, @SpringBootConfiguration |
| Auto Configuration | Spring Boot's ability to configure itself based on the dependencies present |
| Convention over Configuration | Spring Boot uses sensible defaults; override only what you need |
| Starter Dependency | A curated dependency bundle (e.g., spring-boot-starter-web) that pulls in all required libraries with compatible versions |
| Embedded Server | Tomcat is bundled inside the Spring Boot JAR — no separate server installation needed |
Key Observations
- Spring Boot does not replace Spring MVC — it wraps and automates it. All Spring MVC features (Dispatcher Servlet, IoC,
@Autowired, controller annotations) still work exactly the same. - The three Spring Boot advantages are: Dependency Management, Auto Configuration, and Embedded Server.
@SpringBootApplicationinternally contains three annotations and replaces several Spring MVC configuration classes.- Spring Boot scans for components starting from the package of the main class — this is the default "opinionated" behavior.
- Spring Boot packages as a JAR (not WAR) that can be run with
java -jar myapp.jar. - You can still override any Spring Boot default — it is not forced on you.
Common Mistakes
Mistake 1 Thinking Spring Boot Is a Different Framework
1❌ "Spring Boot is separate from Spring MVC"2✅ Spring Boot IS Spring MVC, with automated setup on top.3 Dispatcher Servlet, IoC, @Autowired all still work exactly the same.Mistake 2 Placing Main Class in Wrong Package
1// ❌ Main class in 'com.example' but controllers in 'com.different'2// @ComponentScan will NOT find the controllers — they are in a different package tree!3package com.example;4
5@SpringBootApplication6public class MyApplication { ... }7// Controllers in 'com.different' are NOT scanned1// ✅ Keep main class in the root package; all controllers in sub-packages2package com.example;3
4@SpringBootApplication5public class MyApplication { ... }6// com.example.controller.PaymentController → ✅ scanned7// com.example.service.UserService → ✅ scannedMistake 3 Adding Versions to Starter Dependencies
1<!-- ❌ Don't specify versions for starters — the parent manages them -->2<dependency>3 <groupId>org.springframework.boot</groupId>4 <artifactId>spring-boot-starter-web</artifactId>5 <version>3.0.1</version> <!-- May cause version conflicts! -->6</dependency>7
8<!-- ✅ Let Spring Boot manage the version -->9<dependency>10 <groupId>org.springframework.boot</groupId>11 <artifactId>spring-boot-starter-web</artifactId>12</dependency>Best Practices
- Always use Spring Boot for new projects — it is the standard way to build Spring applications today.
- Keep the main application class in the root package of your project so component scanning works automatically.
- Use starters (
spring-boot-starter-web,spring-boot-starter-data-jpa, etc.) rather than adding individual dependencies manually. - Use
application.propertiesorapplication.ymlto override Spring Boot's default configuration values when needed. - Avoid creating WAR files unless deploying to a legacy external server is required. Prefer the self-contained JAR approach.
- Leverage Spring Boot's embedded Tomcat for local development — it ensures environment consistency between development and production.
Interview Notes
Commonly Asked Interview Questions:
- What is Spring Boot and why was it introduced? — A framework built on top of Spring MVC that eliminates boilerplate configuration. Introduced to solve three Spring MVC problems: manual dependency management, manual configuration, and external server deployment.
- What are the three main advantages of Spring Boot over Spring MVC? — Dependency Management (starters + no manual versions), Auto Configuration (
@SpringBootApplication), and Embedded Server (no WAR, no external Tomcat). - What is
@SpringBootApplication? — A composed annotation that includes@EnableAutoConfiguration,@ComponentScan, and@SpringBootConfiguration. It replaces the need forAppConfigandDispatcherServletInitializerin Spring MVC. - What is a Dispatcher Servlet? — The front controller in Spring MVC (and Spring Boot) that receives all requests and routes them to the correct controller and method using handler mappings.
- What is the difference between IoC and Dependency Injection? — IoC is the principle (framework manages object lifecycle). DI is the implementation (framework injects dependencies). In Spring,
@Autowiredis the DI mechanism that implements IoC. - What is Convention over Configuration? — Spring Boot's approach of providing sensible defaults (e.g., scanning from the main class package, auto-configuring Tomcat) so developers don't need to write configuration code. Defaults can be overridden when needed.
- What is the difference between a WAR and a JAR in Spring Boot? — Traditional Spring MVC packaged as a WAR for external Tomcat. Spring Boot packages as a self-contained JAR with embedded Tomcat — runnable directly with
java -jar. - What is a Spring Boot Starter? — A pre-packaged dependency bundle (like
spring-boot-starter-web) that pulls in all required libraries with compatible, pre-verified versions. - Why is tight coupling a problem, and how does Spring solve it? — Tight coupling (using
newto create dependencies) prevents mocking in unit tests. Spring's@Autowiredlets the framework inject dependencies, which can be replaced with mocks in tests. - Does Spring Boot replace the Dispatcher Servlet? — No. Dispatcher Servlet is still used internally. Spring Boot just configures it automatically — you never have to write the setup code.
Mind Map
Summary
| Stage | Key Innovation | Remaining Problem |
|---|---|---|
| Servlet | Java-based HTTP handling | web.xml, tight coupling, rigid routing, external server |
| Spring MVC | Annotations, IoC/DI, Dispatcher Servlet | Manual config classes, manual dependency versions, external server |
| Spring Boot | Starters, Auto Config, Embedded Server | None of the above — production-ready out of the box |
@SpringBootApplication replaces all manual configuration classes.
3. Embedded Server — Tomcat is embedded; run as a JAR, no WAR deployment needed.End of Chapter — Introduction to Spring Boot
Practice & Implement
Apply what you learned in Introduction to Spring Boot
Spring Boot scans all classes in the package. Simulate this by creating a `ComponentScanner` that uses reflection to find all classes implementing a `Component` interface and prints their names.
Found: UserService Found: EmailService
Mastery check
How well can you recall this?
Finished this lesson?