Spring MVC Tutorial

Core Spring MVC

Spring MVC - Annotation

Spring MVC - Form Handling

Spring MVC with JSTL

Spring MVC with REST API

Spring MVC with Database

Difference between Spring MVC and Spring Boot

Spring MVC and Spring Boot are two modules/frameworks within the larger Spring ecosystem, and while they can be used together, they have distinct roles and features. Here's a breakdown of the differences:

  1. Purpose:

    • Spring MVC:

      • A web module/framework that provides functionalities to build web applications using the Model-View-Controller design pattern.
      • Provides a robust mechanism to handle incoming HTTP requests and route them to appropriate controllers, convert objects to/from JSON, XML, etc., and return views or data as responses.
    • Spring Boot:

      • Simplifies the process of building production-ready applications with minimal effort and reduced boilerplate configuration.
      • Provides a way to "just run" your application. With an embedded server (like Tomcat, Jetty, or Undertow), you don't need to deploy WAR files; a simple Java application with a public static void main method can start your web app.
  2. Configuration:

    • Spring MVC:

      • Typically requires configuration setup, either via XML or Java-based configuration.
      • You'd set up components like view resolvers, handler mappings, and other beans manually or via annotations.
    • Spring Boot:

      • Convention over configuration: Comes with sensible defaults based on the libraries on the classpath.
      • Automatically configures your application based on the included dependencies. For instance, if Spring Boot detects Spring MVC on the classpath, it auto-configures it.
  3. Dependency Management:

    • Spring MVC:
      • You have to manage your project dependencies and ensure version compatibility.
    • Spring Boot:
      • Comes with a spring-boot-starter-parent project which manages versions of common dependencies, ensuring compatibility.
      • Offers "starters" for common tasks like web development, data access, messaging, etc., so you don't have to handpick and declare each library.
  4. Deployment:

    • Spring MVC:
      • You'd typically build a WAR file and deploy it to a servlet container or application server like Tomcat, Jetty, or WildFly.
    • Spring Boot:
      • Provides embedded servers, enabling you to run your application as a standalone Java application.
      • Can still build WAR files if needed, but often unnecessary due to the embedded server.
  5. Tooling and Production Readiness:

    • Spring MVC:
      • Focused solely on building web applications.
    • Spring Boot:
      • Comes with additional tools to monitor and manage production applications (via Spring Boot Actuator).
      • Provides features like health checks, metrics, environment properties inspection out of the box.

Conclusion:

Spring MVC is a web framework, while Spring Boot is a way to simplify setting up and developing Spring applications. Spring Boot applications can use Spring MVC to create web applications or RESTful services. In essence, Spring Boot does not replace Spring MVC but rather complements it, making it easier to use and reducing much of the configuration overhead typically associated with setting up a Spring MVC application.