springBoot2.3-A simple understanding of dependency management and automatic configuration

1. Automatic dependency management

        Basic introduction: springBoot has written a lot of dependencies and version numbers for us in advance. Of course, we can also customize dependencies and version numbers.

1.1 Brief introduction

1. In the introductory case, the parent project is introduced in springBoot's maven.

2. Ctrl + left-click parent, and found that there is an ancestor parent in it. In this ancestor parent, a lot of dependencies and version numbers have been written.

3. Of course, our development does not require so many dependencies to be configured.

4. In the introductory springBoot, we introduced the web scenario dependency. At this time, springBoot will take out the dependencies and version numbers required for web development from the parent.

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

1.2 Scene Launcher

1、见到很多 spring-boot-starter-* : *就某种场景
2、只要引入starter,这个场景的所有常规需要的依赖我们都自动引入
3、SpringBoot所有支持的场景
https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-starter
4、见到的  *-spring-boot-starter: 第三方为我们提供的简化开发的场景启动器。
5、所有场景启动器最底层的依赖
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter</artifactId>
  <version>2.3.4.RELEASE</version>
  <scope>compile</scope>
</dependency>

1.3 How to customize dependencies and version numbers

        After we introduced the web scenario dependency, we found that there is no mysql driver in the default dependency. What should we do at this time?

        1.3.1 Custom dependencies

        There is no mysql driver in spring-boot-starter-web by default. At this time, you can write it yourself in the dependencies of your project ( you don’t need to write the version number , because the parent has already declared it for us)

  • No need to pay attention to the version number, automatic version arbitration
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

        1.3.2 Custom version

        You can configure the following statement in the project maven and that's it (overwriting the original statement)

2. Automatic configuration

springBoot helps us automatically configure a lot, such as the following

2.1 Automatically configure tomcat

        After introducing dependencies, configure tomcat

2.2 Automatically configure springMVC

        After introducing the dependencies, configure springMVC.

        For example:

                2.2.1 Automatically configure common web configurations

                        dispatcherServlet , 

                        View resolver resolver (jump page),

                        characterEcodingFilter() (to prevent garbled page messages on returned pages)

                        Upload and download interceptor

                        ..........etc

2.3 Default package structure

        Components in the package where the main program is located and all sub-packages below it will be scanned in by default.

       Want to change the scan path, @SpringBootApplication(scanBasePackages= "com.atguigu" )

2.4 Load on demand

    • All SpringBoot's automatic configuration functions are in the spring-boot-autoconfigure package.

Guess you like

Origin blog.csdn.net/qq_36684207/article/details/135314265