Spring boot framework learning 5-spring boot web development (1)

The main content of this chapter:

Through the previous study, we understood and quickly completed the first application of spring boot. Spring boot enterprise-level framework, how does spring boot read static resources? What about js folders, css files and png/jpg images? How to customize the message converter? How to customize the configuration of spring mvc? These are what we need in the company. How to solve these? These are explained in detail in the following subsections. Well, now start the first section of spring boot's web development

This section mainly:

1: spring boot automatically configures viewResolver

This article is the fifth spring boot framework learning 5-spring boot web development (1)

Disclaimer: This article is original by Kaige Java (www.kaigejava.com), reprinting is prohibited without permission!

One: Spring boot automatically configures viewResolver to explain

1.1: Under which package is all the automatic configuration of spring boot?

All configurations are under the spring-boot-autoconfigure package. As shown below:

1.2 The specific location of spring bootviewResolver:

具体:org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration

The source code is roughly explained:

1: @conditionalOnClass: Conditional selection annotation

Source code:

The general meaning of the source code comment: Only the class configured in the value can be in the current classpath.

so:

@ConditionalOnClass({ Servlet.class, DispatcherServlet.class,

WebMvcConfigurerAdapter.class }) Meaning:

The current project must contain Servlet, DispatcherServlet, WebMvcConfigurerAdapter three conditions at the same time, webMvcAutoConfiguration will work.

2: @ConditionalOnMissingBean: Create one if it doesn't exist.

Source code comments:

 

Meaning as shown below:

Create one when there is no filter for request.

Please click here to enter image description

3: View the WebMvcAutoConfiguration source code that we are familiar with

3.1: handlers for resource addition processing:

3.2 Validation related to validator

3.3 Welcome page related:

The source code explanation is relatively slow, so this section wants to explain it here. Next, I will explain a key point InternalResourceViewResolver and reading static resource files. Everyone is welcome to continue learning.

Other articles in this series:

Spring boot framework learns important annotations to master before school (1) - spring's java configuration method

Spring boot framework learns important annotations to master before school (2) - configure spring through java configuration

Spring boot framework learns important annotations before school (3) - reading external resource configuration files through annotations

Spring boot framework learns important annotations before school (4) - reading external resource configuration files through annotations 2

Spring boot framework learning 1 - know spring boot and quick start

Spring boot framework learning 2-spring boot core (1)

Spring boot framework learning 3-spring boot core (2)

Spring boot framework learning 5-spring boot web development (1)

Welcome to the public account of Kaige: Kaige Java

Welcome to Kaige's personal website: www.kaigejava.com

Source of this article: http://www.kaigejava.com/article/detail/53

Spring boot series tutorial address: http://kaigejava.com/article/list?cateid=3

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326687782&siteId=291194637