“Spring Boot 自动配置特性”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) |
Jihongchang(讨论 | 贡献) |
||
第63行: | 第63行: | ||
</servlet-mapping> | </servlet-mapping> | ||
</syntaxhighlight>为什么在 Spring Boot 出现之后,不进行如上的配置也可以进行使用;如果这些配置已经在 Spring Boot 内部实现了,是怎么实现的? | </syntaxhighlight>为什么在 Spring Boot 出现之后,不进行如上的配置也可以进行使用;如果这些配置已经在 Spring Boot 内部实现了,是怎么实现的? | ||
+ | |||
+ | ==== 打印容器中所有的 bean ==== | ||
+ | <syntaxhighlight lang="java"> | ||
+ | package io.github.jihch.boot; | ||
+ | |||
+ | import org.springframework.boot.SpringApplication; | ||
+ | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
+ | import org.springframework.context.ConfigurableApplicationContext; | ||
+ | |||
+ | |||
+ | /** | ||
+ | * 主程序类 | ||
+ | * @SpringBootApplication:这是一个 Spring Boot 应用 | ||
+ | */ | ||
+ | @SpringBootApplication | ||
+ | public class MainApplication { | ||
+ | |||
+ | public static void main(String[] args) { | ||
+ | //1、返回 IOC 容器 | ||
+ | ConfigurableApplicationContext context = SpringApplication.run(MainApplication.class, args); | ||
+ | |||
+ | //2、查看容器里面的组件 | ||
+ | String[] beanDefinitionNames = context.getBeanDefinitionNames(); | ||
+ | for (String name : beanDefinitionNames) { | ||
+ | System.out.println(name); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </syntaxhighlight><syntaxhighlight lang="console"> | ||
+ | requestMappingHandlerAdapter | ||
+ | requestMappingHandlerMapping | ||
+ | welcomePageHandlerMapping | ||
+ | mvcConversionService | ||
+ | mvcValidator | ||
+ | mvcContentNegotiationManager | ||
+ | mvcPathMatcher | ||
+ | mvcUrlPathHelper | ||
+ | viewControllerHandlerMapping | ||
+ | beanNameHandlerMapping | ||
+ | routerFunctionMapping | ||
+ | resourceHandlerMapping | ||
+ | mvcResourceUrlProvider | ||
+ | defaultServletHandlerMapping | ||
+ | handlerFunctionAdapter | ||
+ | mvcUriComponentsContributor | ||
+ | httpRequestHandlerAdapter | ||
+ | simpleControllerHandlerAdapter | ||
+ | handlerExceptionResolver | ||
+ | mvcViewResolver | ||
+ | mvcHandlerMappingIntrospector | ||
+ | org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter | ||
+ | defaultViewResolver | ||
+ | viewResolver | ||
+ | requestContextFilter | ||
+ | org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration | ||
+ | formContentFilter | ||
+ | org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$ClassProxyingConfiguration | ||
+ | org.springframework.boot.autoconfigure.aop.AopAutoConfiguration | ||
+ | org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration | ||
+ | applicationAvailability | ||
+ | org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration | ||
+ | org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration | ||
+ | lifecycleProcessor | ||
+ | spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties | ||
+ | org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration | ||
+ | standardJacksonObjectMapperBuilderCustomizer | ||
+ | spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties | ||
+ | org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration | ||
+ | jacksonObjectMapperBuilder | ||
+ | org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$ParameterNamesModuleConfiguration | ||
+ | parameterNamesModule | ||
+ | org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration | ||
+ | jacksonObjectMapper | ||
+ | org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration | ||
+ | jsonComponentModule | ||
+ | org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration | ||
+ | stringHttpMessageConverter | ||
+ | org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration | ||
+ | mappingJackson2HttpMessageConverter | ||
+ | org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration | ||
+ | org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration | ||
+ | messageConverters | ||
+ | org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration | ||
+ | spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties | ||
+ | org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration | ||
+ | taskSchedulerBuilder | ||
+ | spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties | ||
+ | org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration | ||
+ | restTemplateBuilder | ||
+ | org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration | ||
+ | tomcatWebServerFactoryCustomizer | ||
+ | org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration | ||
+ | org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration | ||
+ | characterEncodingFilter | ||
+ | localeCharsetMappingsCustomizer | ||
+ | org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration | ||
+ | multipartConfigElement | ||
+ | multipartResolver | ||
+ | spring.servlet.multipart-org.springframework.boot.autoconfigure.web.servlet.MultipartProperties | ||
+ | org.springframework.aop.config.internalAutoProxyCreator | ||
+ | |||
+ | </syntaxhighlight> |
2023年2月2日 (四) 08:46的版本
https://www.bilibili.com/video/BV19K4y1L7MT/?p=7
怎么自动配好 Tomcat的?
怎么引入 tomcat 依赖的?
boot-01-helloworld - pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
spring-boot-starter-web-x.x.x.RELEASE.pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>2.3.4.RELEASE</version>
<scope>compile</scope>
</dependency>
自动配置好 Spring MVC
spring-boot-starter-web-x.x.x.RELEASE.pom
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.2.9.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.2.9.RELEASE</version>
<scope>compile</scope>
</dependency>
思考:在 Spring Boot 出现之前,使用 Spring MVC 要有哪些配置?
web.xml
<!--配置DispatcherServlet -->
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 配置SpringMVC需要加载的配置文件 spring-mvc.xml -->
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<!--默认匹配所有的请求 -->
<url-pattern>/</url-pattern>
</servlet-mapping>
为什么在 Spring Boot 出现之后,不进行如上的配置也可以进行使用;如果这些配置已经在 Spring Boot 内部实现了,是怎么实现的?
打印容器中所有的 bean
package io.github.jihch.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
/**
* 主程序类
* @SpringBootApplication:这是一个 Spring Boot 应用
*/
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
//1、返回 IOC 容器
ConfigurableApplicationContext context = SpringApplication.run(MainApplication.class, args);
//2、查看容器里面的组件
String[] beanDefinitionNames = context.getBeanDefinitionNames();
for (String name : beanDefinitionNames) {
System.out.println(name);
}
}
}
requestMappingHandlerAdapter
requestMappingHandlerMapping
welcomePageHandlerMapping
mvcConversionService
mvcValidator
mvcContentNegotiationManager
mvcPathMatcher
mvcUrlPathHelper
viewControllerHandlerMapping
beanNameHandlerMapping
routerFunctionMapping
resourceHandlerMapping
mvcResourceUrlProvider
defaultServletHandlerMapping
handlerFunctionAdapter
mvcUriComponentsContributor
httpRequestHandlerAdapter
simpleControllerHandlerAdapter
handlerExceptionResolver
mvcViewResolver
mvcHandlerMappingIntrospector
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter
defaultViewResolver
viewResolver
requestContextFilter
org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration
formContentFilter
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$ClassProxyingConfiguration
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration
org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration
applicationAvailability
org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration
org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration
lifecycleProcessor
spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration
standardJacksonObjectMapperBuilderCustomizer
spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration
jacksonObjectMapperBuilder
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$ParameterNamesModuleConfiguration
parameterNamesModule
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration
jacksonObjectMapper
org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
jsonComponentModule
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration
stringHttpMessageConverter
org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration
mappingJackson2HttpMessageConverter
org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration
org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration
messageConverters
org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration
spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties
org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration
taskSchedulerBuilder
spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties
org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration
restTemplateBuilder
org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration
tomcatWebServerFactoryCustomizer
org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration
org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration
characterEncodingFilter
localeCharsetMappingsCustomizer
org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration
multipartConfigElement
multipartResolver
spring.servlet.multipart-org.springframework.boot.autoconfigure.web.servlet.MultipartProperties
org.springframework.aop.config.internalAutoProxyCreator