Chapter one introduction
1.1 Spring Study
1.1.1 Recognition Spring
Suppose you are ordered to use Spring Develop a simple one Hello World Web Applications . What to do ？
1、 A project structure , One of them contains necessary dependencies Maven perhaps Gradle Build file , At least Spring MVC and Servlet API These dependencies .
2、 One web.xml file （ Or a WebApplicationInitializer Realization ）, It states Spring Of DispatcherServlet.
3、 One is enabled Spring MVC Of Spring To configure .
4、 A controller class , With “Hello World” Respond to HTTP request .
5、 One for deploying applications Web application server , such as Tomcat.
The most unacceptable thing is , There is only one thing on this list that is and Hello World Function related , I.e. controller , The rest is Spring Developed Web Common templates required for applications . Since all Spring Web All applications use it
People , So why do you have to provide these things ？
Suppose you just need the controller .SpringBoot Will take care of the logistics of executing the application , No configuration required 、web.xml、 Build instructions 、 There's not even an application server .
1.1.2 Spring Boot Essentials
Spring Boot Of Four cores ：
- Automatic configuration ： For many Spring Common application functions of applications ,SpringBoot It can automatically provide relevant configuration .
- Start relying on ： tell Spring Boot What functions are needed , It can bring in the needed Libraries .
- Command line interface ：SpringBoot Optional features , You just need to write code to complete the application , No need to build traditional projects .
- Actuator： It allows people to go deep into the running Spring Boot Applications .
1、 Automatic configuration
Spring Boot These common configuration scenarios are automatically configured . If Spring Boot In the application of Classpath Found in H2 Database database , Then it automatically configures an embedded system H2 database . If in Classpath Found in
JdbcTemplate, Then it will configure you with a JdbcTemplate Of Bean. You don't have to worry about that Bean Configuration of ,Spring Boot Will be ready , It can be injected into your Bean in .Spring Boot It's much more than embedded databases and JdbcTemplate, It has a lot of ways to help you reduce the configuration burden , These automatic configurations involve Java Persistence API（ Java Persistence API, JPA）、 Thymeleaf Templates 、 Safety and Spring MVC.
2、 Start relying on
Spring Boot adopt Start relying on Help with dependency management of projects . Starting dependence is actually special Maven Dependence and Gradle rely on , Using transitive dependency resolution , Aggregate common libraries together , It's made up of several customized features
Dependence . In short , You imported a dependency A, rely on A Other required dependencies will be introduced into the project based on dependency passing , In addition to reducing the number of dependencies , One dependency can replace one type of dependency ,SpringBoot The starting dependency will also automatically resolve the conflicts caused by version incompatibility .
3、 Command line interface