SoFunction
Updated on 2025-03-02

The difference and description of Spring, SpringMvc and SpringBoot

A brief introduction to the three

1、Spring

Spring is a one-stop lightweight Java development framework with the core of control inversion (IOC) and tangent-oriented (AOP). It provides a variety of configuration solutions and basic architectural support for development WEB layer (SpringMvc), business layer (Ioc), persistence layer (JdbcTemplate), etc.

It contains some good features, such as dependency injection and out-of-the-box modules, such as: Spring JDBC, Spring MVC, Spring Security, Spring AOP, Spring ORM, Spring Test.

These modules can greatly reduce the development time of the application. For example, in the early stages of Java Web development, we needed to write a lot of duplicate code to insert records into the data source.

But by using the JDBCTemplate of the Spring JDBC module, we can simplify it to just a few simple configurations or a few lines of code.

2、SpringMvc

SpringMvc is an MVC framework developed by enterprise WEB based on Spring, covering areas including front-end view development, file configuration, and back-end interface logic.
For the development of the system, XML, config and other configurations are relatively complicated and complex, and are part of the development of the WEB layer in the Spring framework.

3、SpringBoot

Compared with the SpringMvc framework, the SpringBoot framework focuses more on the development of microservice backend interfaces. Of course, it also supports front-end development through Template and other methods. At the same time, it follows the default over configuration, simplifies the plug-in configuration process and does not require configuring XML. Compared with springmvc, it greatly simplifies the configuration process.

Here are some features in Spring Boot:

  1. Use the starter dependency to simplify construction and complex application configuration.
  2. It can directly start main function, embedded web server, avoiding the complexity of application deployment, Metrics metrics, Health check health check and external configuration.
  3. Automatically configure Spring functionality as much as possible.

2. SpringBoot upgrade items

2.1 Maven dependencies

First, let's take a look at the minimum dependencies required to create a web application using SpringMvc:

<dependency>
    <groupId></groupId>
    <artifactId>spring-web</artifactId>
    <version>5.1.</version>
</dependency>
<dependency>
    <groupId></groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>5.1.</version>
</dependency>

Unlike SpringMvc, Spring Boot only requires one dependency to get up and run a web application:

<dependency>
    <groupId></groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.0.</version>
</dependency>

During build, all other dependencies will be automatically added to the final archive. Spring Boot provides many introductory dependencies for different Spring modules. Some of the most commonly used are:

  1. spring-boot-starter-data-jpa
  2. spring-boot-starter-security
  3. spring-boot-starter-test
  4. spring-boot-starter-web
  5. spring-boot-starter-thymeleaf

2.2 MVC configuration

Let's explore the configuration required to create JSP web applications using SpringMvc and Spring Boot.

public class MyWebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext container) {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        ("");

        (new ContextLoaderListener(context));

         dispatcher = ("dispatcher", new DispatcherServlet(context));

        (1);
        ("/");
    }
}

We also need to add the @EnableWebMvc annotation to the @Configuration annotation class and define a view parser to parse the views returned from the controller:

@EnableWebMvc
@Configuration
public class ClientWebConfig implements WebMvcConfigurer {
   @Bean
   public ViewResolver viewResolver() {
      InternalResourceViewResolver bean = new InternalResourceViewResolver();
          ();
          ("/WEB-INF/view/");
          (".jsp");
      return bean;
   }
}

Compared to all of this, once we add Spring boot web starter, Spring Boot only needs some properties to make the above work:

=/WEB-INF/jsp/
=.jsp

All Spring configurations above are automatically included by adding a Boot web starter with a process called auto-configuration.

This means that Spring Boot will automatically scan for dependencies, properties, and beans present in the application and enable the corresponding configuration based on these.

2.3 Template Engine Configuration

Let’s take a look at how to configure the Thymeleaf template engine in SpringMvc and Spring Boot. What is the difference between the two?

In SpringMvc we need to add thymeleaf-spring5 dependencies and some configurations for the view parser:

@Configuration
@EnableWebMvc
public class MvcWebConfig implements WebMvcConfigurer {

    @Autowired
    private ApplicationContext applicationContext;

    @Bean
    public SpringResourceTemplateResolver templateResolver() {
        SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
            (applicationContext);
            ("/WEB-INF/views/");
            (".html");
        return templateResolver;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
            (templateResolver());
            (true);
        return templateEngine;
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
            (templateEngine());
        (resolver);
    }
}

Spring Boot only requires spring-boot-starter-thymeleaf dependencies to enable Thymeleaf support in web applications.

Once the dependencies are added successfully, we can add the templates to the src/main/resources/templates folder and Spring Boot will automatically display them.

2.4 Security Configuration

For simplicity, we will see how to enable default HTTP Basic authentication using SpringMvc and Spring Boot frameworks.

Let's first look at the dependencies and configurations required to enable Security using SpringMvc.

SpringMvc requires the standard spring-security-web and spring-security-config dependencies to set up Security in the application.

Next, we need to add a class that extends WebSecurityConfigurerAdapter and use @EnableWebSecurity annotation:

@Configuration
@EnableWebSecurity
public class CustomWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        ()
            .withUser("user1")
            .password(passwordEncoder().encode("user1Pass"))
            .authorities("ROLE_USER");
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        ().anyRequest().authenticated().and().httpBasic();
    }


    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

Similarly, Spring Boot requires these dependencies to make it work. But we just need to define the dependency of spring-boot-starter-security, which will automatically add all related dependencies to the classpath.

2.5 Application Bootstrap

The basic difference between application boot in SpringMvc and Spring Boot is servlet.

SpringMvc uses or SpringServletContainerInitializer as its boot entry point. SpringBoot only uses Servlet 3 to boot the program.

First, let’s talk about SpringMvc boot

Method 1: Boot method

  1. Servlet container (server) read
  2. The DispatcherServlet defined in is instantiated by a container
  3. DispatcherServlet creates WebApplicationContext by reading WEB-INF / {servletName} -
  4. Finally, the DispatcherServlet registers beans defined in the application context

Method 2: servlet 3+ boot method

  1. Container searches for the class that implements ServletContainerInitializer and executes it
  2. SpringServletContainerInitializer finds a subclass that implements the class WebApplicationInitializer
  3. WebApplicationInitializer creates a session using XML or context @Configuration class
  4. WebApplicationInitializer creates a DispatcherServlet, using the context created previously.

Let's talk about Spring Boot

The entry point of a Spring Boot application is the class annotated with @SpringBootApplication:

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

By default, Spring Boot uses embedded containers to run applications. In this case, Spring Boot uses the public static void main entry point to start the embedded web server.

In addition, it is also responsible for binding Servlet, Filter, and ServletContextInitializer beans from the application context to the embedded servlet container.

Another feature of Spring Boot is that it automatically scans components in subpackages of all classes in the same package or Main class.

Spring Boot provides the option to deploy it as a web archive in an external container. In this case, we have to extend SpringBootServletInitializer:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    // ...
}

The external Servlet container looks for Main-class defined in the META-INF file of the web archive file, and the SpringBootServletInitializer will be responsible for binding the Servlet, Filter and ServletContextInitializer.

2.6 Packaging and deployment

Finally, let's see how to package and deploy applications. Both frameworks support common package management technologies such as Maven and Gradle. But in terms of deployment, these frameworks vary greatly.

For example, the Spring Boot Maven plugin provides Spring Boot support in Maven. It also allows package executable jar or war archives and run the application "in-place".

Some of the advantages of Spring Boot in a deployment environment compared to SpringMvc include

  1. Embedded container support is provided
  2. Run jar independently using command java -jar
  3. When deploying in external containers, you can choose to exclude dependencies to avoid potential jar conflicts
  4. Flexible options for specifying configuration files during deployment
  5. Random port generation for integration testing

3. Summary

(1) Spring framework is like a family, with many derivative products such as boot, security, jpa, etc. But their foundations are Spring's ioc, aop, etc. IOC provides dependency injection containers, AOP solves cross-sectional programming, and then implements advanced features of other extended products based on both.

(2) SpringMvc mainly solves the problem of WEB development. It is an MVC framework based on Servlet. Through XML configuration, it uniformly develops front-end views and back-end logic.

(3) Because the configuration of SpringMvc is very complex, various XML, JavaConfig, and servlets are complicated to handle. In order to simplify the use of developers, SpringBoot framework was creatively launched, which is better than configuration by default, simplifying the configuration process of SpringMvc. But unlike SpringMvc, SpringBoot focuses on the development of single-body microservice interfaces and decoupling from the front-end, but SpringBoot can also be developed together in the front-end and back-end development of SpringMvc.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.