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+------------------+ | vHTTP 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):
@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-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:
- XML configuration files (web.xml, applicationContext.xml)
- Manual DispatcherServlet setup
- External Tomcat server installation and deployment
- Dependency version management
- 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:
@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:
@SpringBootApplicationpublic class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); }}Starter Dependencies
Spring Boot bundles common dependencies into “starters”:
<!-- 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 code2. Package as WAR3. Install Tomcat on server4. Deploy WAR to Tomcat5. Start Tomcat
Spring Boot:1. Write code2. Package as JAR3. Run: java -jar app.jarProduction Features
Spring Boot Actuator adds:
- Health endpoints (
/actuator/health) - Metrics (
/actuator/metrics) - Environment info
- Graceful shutdown
What They Each Provide
| Feature | Spring MVC | Spring Boot |
|---|---|---|
| DispatcherServlet | Yes (manual config) | Yes (auto-configured) |
| @Controller/@RestController | Yes | Yes (inherits from MVC) |
| Request mapping | Yes | Yes (inherits from MVC) |
| View resolution | Yes | Yes (inherits from MVC) |
| Auto-configuration | No | Yes |
| Embedded server | No (needs external) | Yes (Tomcat/Jetty/Undertow) |
| Starter dependencies | No | Yes |
| Production metrics | Manual | Actuator built-in |
| Quick start | No (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 DispatcherServlet2. DispatcherServlet consults HandlerMapping to find controller3. HandlerMapping returns HandlerExecutionChain (controller + interceptors)4. Pre-processing interceptors execute5. Controller method executes6. Controller returns ModelAndView or @ResponseBody7. Post-processing interceptors execute8. ViewResolver resolves view name to actual view9. View renders (if applicable)10. Response sent to clientWhen something breaks in Spring Boot, this is what’s happening under the hood.
Common Mistakes I See
| Mistake | Why It’s Wrong | What to Do Instead |
|---|---|---|
| Think they’re alternatives | They’re complementary, not competing | Learn both together |
| Skip Spring MVC fundamentals | Debugging becomes impossible when Boot’s defaults fail | Learn DispatcherServlet, request lifecycle |
| Over-configure Spring Boot | Boot’s defaults are well-tested | Customize only when needed |
| Never learn XML configuration | You’ll struggle with legacy code | Understand traditional Spring setup |
| Memorize annotations blindly | No understanding of what happens | Read Spring MVC documentation |
When to Learn What
I recommend this order:
1. Java fundamentals (OOP, interfaces, collections) | v2. Spring Core (DI, IoC, @Component, @Bean) | v3. Spring MVC basics (DispatcherServlet, @Controller, request lifecycle) | v4. Spring Boot (start building real applications quickly) | v5. 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:
- 👨💻 Spring Framework Official Documentation
- 👨💻 Spring Boot Reference Guide
- 👨💻 Baeldung Spring MVC Tutorial
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments