springboot series 2 automatic assembly principle analysis-official documents combined with source code

1 Environmental preparation

1.1 Build a simple project

Start with a web project to analyze automatic assembly, so we need to quickly build a Hello World

1.2 Official documentation

Official website link:
https://docs.spring.io/spring-boot/docs/2.4.4-SNAPSHOT/reference/html/using-spring-boot.html#using-boot-configuration-classes
Insert picture description here

According to the official documentation:
as long as you mark @SpringBootApplication on the startup class, you can have the following 3 annotation functions

  1. @EnableAutoConfiguration: Automatic import configuration function
  2. @ComponentScan: Scan the components of the annotated package
  3. @Configuration: Annotate that this is a configuration class

1.3 View source code

Automatic configuration key points

1. Automatic assembly of components

xxxAutoConfiguration

2. Automatic configuration

xxxProperties, through which you can customize configuration items

3.dubug ture

See which components are in effect

1. Location of static resources

Remarks: Based on the version number V2.4.3, the location of
different versions may be somewhat different

1. Default location (loaded at startup)

(1). Location

  • classpath:/META-INF/resources/webjars/
  • classpath:/META-INF/resources/
  • classpath:/resources/
  • classpath:/static/
  • classpath:/public/

(2) Priority

resources> static (default)> public
generally rarely use webjars/

(3). Corresponding source code

  • WebMvcAutoConfiguration
    Insert picture description here

  • WebProperties
    Insert picture description here

2. Custom (will override the default configuration)

(1) Customize in the configuration file

application.properties

spring.mvc.static-path-pattern=/自定义路径

(2) Corresponding source code

  • WebMvcProperties
    Insert picture description here

Guess you like

Origin blog.csdn.net/dabaoting/article/details/114013186