Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.

This article is mainly about Spring, Spring MVC, and Spring Boot. They are not a competing state, but can be applied in different scenarios.

What problem does Spring solve?

The core features in Spring are IOC and DI, and using IOC and DI properly can write low-coupling applications that make unit testing easy.

In addition, Spring provides many functional modules based on DI, such as Spring JDBC, Spring MVC, Spring AOP, Spring ORM, Spring JMS, and Spring Test. You may not need every module. However, the use of these modules can reduce the amount of repetitive code and improve unit testing efficiency.

Finally, Spring can easily integrate with other frameworks. Hibernate, Mybatis or Junit.

What problem does Spring MVC solve?

The Spring MVC framework provides a decoupled approach to developing Web applications. Web applications can be easily developed with simple concepts such as Dispatcher servlets, ModelandViews, and view parsers.

Why do we need Spring Boot?

Spring-based projects have many configurations. When using Spring MVC, we need to configure component scanning, front segment controller Servlet, and view parser. When using Hibernate, we need to configure data sources, entity factories, transaction management, etc.

1 Spring Boot automatic configuration

Spring Boot can view the frameworks available on the classpath as well as the existing configuration of the application. Based on this, Spring Boot provides the basic configuration required to use these framework applications. This is called automatic configuration.

If you find Hibernate or Spring MVC JARS in your classpath, the dataSource and Dispatcher servlets are automatically configured.

2 The Starter module automatically builds project dependencies

When we start a new project, we need to select the technology. However, we need to consider whether the technology of different modules is compatible with each other. With the Starter model, we no longer have to deal with the version problem ourselves.

If we want to build a Web project, we can use the Spring Boot Start Web module.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
Copy the code

This one dependency contains the basic dependencies we use to build web projects, and as developers we don’t need to think about what dependencies we choose and what version of dependencies.

Not only web modules, but also starter modules such as Test, JDBC, Security, data-JPA, etc. The goal of Spring Boot is to get you to build a project as quickly as possible.