Skip to content

What Is the Difference Between Spring Boot and Spring MVC? A Complete Guide for Java Developers

Problem

When I first started learning Spring, I kept seeing “Spring Boot” and “Spring MVC” mentioned together, and I couldn’t figure out the relationship. Are they alternatives? Do I need to learn both? Which one should I start with?

I see this confusion everywhere in online forums. Beginners ask whether they should learn “Spring MVC or Spring Boot,” as if they’re competing frameworks. This misunderstanding leads to poor learning paths and, worse, shallow knowledge that falls apart when things break.

The core issue: most developers don’t realize Spring Boot uses Spring MVC under the hood.

The Relationship: Engine vs Car

The simplest way I’ve found to explain this:

+-----------------------------+
| Spring Boot | <-- The car (ready to drive)
| +-----------------------+ |
| | Spring MVC | | <-- The engine (handles requests)
| +-----------------------+ |
| |
| +-----------------------+ |
| | Auto-configuration | | <-- The "autopilot" features
| +-----------------------+ |
| |
| +-----------------------+ |
| | Embedded Tomcat | | <-- Built-in server
| +-----------------------+ |
| |
| +-----------------------+ |
| | Starter Dependencies| | <-- Bundled libraries
| +-----------------------+ |
+-----------------------------+

Spring MVC is the web framework that handles HTTP requests and responses. Spring Boot is a convenience layer that configures Spring MVC automatically and bundles everything you need into a runnable application.

They’re not alternatives—they work together.

What Spring MVC Actually Does

Spring MVC (Model-View-Controller) is the core web framework in Spring. It handles:

HTTP Request
|
v
+------------------+
| DispatcherServlet| <-- Front controller (receives all requests)
+------------------+
|
v
+------------------+
| Controller | <-- Your @GetMapping/@PostMapping methods
+------------------+
|
v
+------------------+
| Service | <-- Business logic
+------------------+
|
v
+------------------+
| Repository | <-- Data access
+------------------+
|
v
HTTP Response (JSON/View)

The key components of Spring MVC:

DispatcherServlet - The front controller that routes every incoming HTTP request to the appropriate controller method.

@Controller / @RestController - Classes that handle web requests. The difference: @RestController adds @ResponseBody automatically for JSON responses.

@RequestMapping / @GetMapping / @PostMapping - Annotations that map URLs to Java methods.

Here’s a pure Spring MVC controller (without Spring Boot):

UserController.java
@Controller
@RequestMapping("/users")
public class UserController {
private final UserService userService;
@Autowired
public UserController(UserService userService) {
this.userService = userService;
}
@GetMapping("/{id}")
public String getUser(@PathVariable Long id, Model model) {
User user = userService.findById(id);
model.addAttribute("user", user);
return "user-view"; // Returns a view name (e.g., JSP/Thymeleaf)
}
}

Without Spring Boot, you’d need to configure all this manually:

web.xml
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<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-mvc-config.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>

This is what Spring Boot eliminates—the verbose XML configuration.

What Spring Boot Adds

Spring Boot was created to solve a real problem: Spring configuration was painful. Every new Spring MVC project required:

  1. XML configuration files (web.xml, applicationContext.xml)
  2. Manual DispatcherServlet setup
  3. External Tomcat server installation and deployment
  4. Dependency version management
  5. Boilerplate code for common setups

Spring Boot’s auto-configuration detects what’s on your classpath and sets things up automatically.

Auto-Configuration

When Spring Boot finds spring-boot-starter-web on your classpath, it automatically:

  • Configures a DispatcherServlet
  • Sets up a ViewResolver
  • Configures JSON serialization (Jackson)
  • Enables static resource handling
  • Starts an embedded Tomcat server

The same controller in Spring Boot requires zero XML:

UserController.java
@RestController
@RequestMapping("/api/users")
public class UserController {
private final UserService userService;
// Spring Boot auto-injects (no @Autowired needed with single constructor)
public UserController(UserService userService) {
this.userService = userService;
}
@GetMapping("/{id}")
public ResponseEntity<User> getUser(@PathVariable Long id) {
return userService.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping
public ResponseEntity<User> createUser(@Valid @RequestBody CreateUserRequest request) {
User user = userService.create(request);
return ResponseEntity.status(HttpStatus.CREATED).body(user);
}
}

And the entire application starts with one class:

Application.java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

Starter Dependencies

Spring Boot bundles common dependencies into “starters”:

pom.xml
<!-- Instead of individually adding:
spring-webmvc, jackson-databind, tomcat, hibernate-validator, etc.
You add one starter: -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

This pulls in ~15 dependencies with compatible versions.

Embedded Server

No more installing Tomcat separately. Spring Boot includes an embedded server:

Traditional Spring MVC:
1. Write code
2. Package as WAR
3. Install Tomcat on server
4. Deploy WAR to Tomcat
5. Start Tomcat
Spring Boot:
1. Write code
2. Package as JAR
3. Run: java -jar app.jar

Production Features

Spring Boot Actuator adds:

  • Health endpoints (/actuator/health)
  • Metrics (/actuator/metrics)
  • Environment info
  • Graceful shutdown

What They Each Provide

FeatureSpring MVCSpring Boot
DispatcherServletYes (manual config)Yes (auto-configured)
@Controller/@RestControllerYesYes (inherits from MVC)
Request mappingYesYes (inherits from MVC)
View resolutionYesYes (inherits from MVC)
Auto-configurationNoYes
Embedded serverNo (needs external)Yes (Tomcat/Jetty/Undertow)
Starter dependenciesNoYes
Production metricsManualActuator built-in
Quick startNo (setup required)Yes (run in seconds)

Why Learning Both Matters

I’ve seen developers who only learn Spring Boot annotations without understanding Spring MVC. They hit a wall when:

Debugging complex issues - When a request fails, you need to understand the request lifecycle. Which interceptor runs first? Why isn’t my @ExceptionHandler catching this?

Performance tuning - Spring Boot’s defaults are good, but production applications need customization. Understanding the underlying MVC layer helps you tune correctly.

Working with legacy code - Many enterprises still run older Spring MVC applications. You’ll encounter XML configurations and manual setups.

Interview questions - “Explain the Spring MVC request lifecycle” is a common question. If you only know Spring Boot, you’ll struggle.

Here’s the Spring MVC request lifecycle you should understand:

1. Request arrives at DispatcherServlet
2. DispatcherServlet consults HandlerMapping to find controller
3. HandlerMapping returns HandlerExecutionChain (controller + interceptors)
4. Pre-processing interceptors execute
5. Controller method executes
6. Controller returns ModelAndView or @ResponseBody
7. Post-processing interceptors execute
8. ViewResolver resolves view name to actual view
9. View renders (if applicable)
10. Response sent to client

When something breaks in Spring Boot, this is what’s happening under the hood.

Common Mistakes I See

MistakeWhy It’s WrongWhat to Do Instead
Think they’re alternativesThey’re complementary, not competingLearn both together
Skip Spring MVC fundamentalsDebugging becomes impossible when Boot’s defaults failLearn DispatcherServlet, request lifecycle
Over-configure Spring BootBoot’s defaults are well-testedCustomize only when needed
Never learn XML configurationYou’ll struggle with legacy codeUnderstand traditional Spring setup
Memorize annotations blindlyNo understanding of what happensRead Spring MVC documentation

When to Learn What

I recommend this order:

1. Java fundamentals (OOP, interfaces, collections)
|
v
2. Spring Core (DI, IoC, @Component, @Bean)
|
v
3. Spring MVC basics (DispatcherServlet, @Controller, request lifecycle)
|
v
4. Spring Boot (start building real applications quickly)
|
v
5. Deep dive into Spring MVC internals (when debugging or optimizing)

Start with Spring Boot for productivity. But invest time in Spring MVC fundamentals. I think of it like learning to drive an automatic car (Spring Boot) versus understanding how the engine works (Spring MVC). You can drive without knowing the engine, but when something breaks, you’ll need that knowledge.

Summary

In this post, I explained that Spring Boot and Spring MVC are not alternatives—Spring Boot provides auto-configuration and convenience on top of Spring MVC.

The key points are:

  • Spring MVC handles HTTP requests, routing, and responses (the engine)
  • Spring Boot auto-configures Spring MVC and adds embedded servers, starters, and production features (the car)
  • Learn Spring Boot first for quick productivity, but understand Spring MVC for debugging and career growth
  • Don’t treat them as competitors—you use both together in every Spring Boot web application

I spent too long confused by this distinction. Once I understood that Spring Boot is just Spring MVC with sensible defaults and less boilerplate, everything clicked. If you’re learning Spring now, start with Boot but don’t skip the fundamentals.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments