查看“Spring Boot 自动配置特性”的源代码
←
Spring Boot 自动配置特性
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看和复制此页面的源代码。
https://www.bilibili.com/video/BV19K4y1L7MT/?p=7 === 怎么自动配好 Tomcat的? === ==== 怎么引入 tomcat 依赖的? ==== boot-01-helloworld - pom.xml<syntaxhighlight lang="xml"> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </syntaxhighlight> spring-boot-starter-web-x.x.x.RELEASE.pom<syntaxhighlight lang="xml"> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <version>2.3.4.RELEASE</version> <scope>compile</scope> </dependency> </syntaxhighlight> === 自动配置好 Spring MVC === spring-boot-starter-web-x.x.x.RELEASE.pom<syntaxhighlight lang="xml"> <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> </syntaxhighlight> === 思考:在 Spring Boot 出现之前,使用 Spring MVC 要有哪些配置? === web.xml<syntaxhighlight lang="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> </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(); Arrays.sort(beanDefinitionNames); for (String name : beanDefinitionNames) { System.out.println(name); } } } </syntaxhighlight><syntaxhighlight lang="console"> applicationAvailability applicationTaskExecutor basicErrorController beanNameHandlerMapping beanNameViewResolver characterEncodingFilter conventionErrorViewResolver defaultServletHandlerMapping defaultViewResolver dispatcherServlet dispatcherServletRegistration error errorAttributes errorPageCustomizer errorPageRegistrarBeanPostProcessor formContentFilter handlerExceptionResolver handlerFunctionAdapter helloController httpRequestHandlerAdapter jacksonObjectMapper jacksonObjectMapperBuilder jsonComponentModule lifecycleProcessor localeCharsetMappingsCustomizer mainApplication mappingJackson2HttpMessageConverter messageConverters multipartConfigElement multipartResolver mvcContentNegotiationManager mvcConversionService mvcHandlerMappingIntrospector mvcPathMatcher mvcResourceUrlProvider mvcUriComponentsContributor mvcUrlPathHelper mvcValidator mvcViewResolver org.springframework.aop.config.internalAutoProxyCreator org.springframework.boot.autoconfigure.AutoConfigurationPackages org.springframework.boot.autoconfigure.aop.AopAutoConfiguration org.springframework.boot.autoconfigure.aop.AopAutoConfiguration$ClassProxyingConfiguration org.springframework.boot.autoconfigure.availability.ApplicationAvailabilityAutoConfiguration org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration org.springframework.boot.autoconfigure.context.LifecycleAutoConfiguration org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration$StringHttpMessageConverterConfiguration org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration org.springframework.boot.autoconfigure.http.JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$Jackson2ObjectMapperBuilderCustomizerConfiguration org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperConfiguration org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$ParameterNamesModuleConfiguration org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration$TomcatWebServerFactoryCustomizerConfiguration org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletConfiguration org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$DefaultErrorViewResolverConfiguration org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration$TomcatWebSocketConfiguration org.springframework.boot.context.internalConfigurationPropertiesBinder org.springframework.boot.context.internalConfigurationPropertiesBinderFactory org.springframework.boot.context.properties.BoundConfigurationProperties org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor org.springframework.context.annotation.internalAutowiredAnnotationProcessor org.springframework.context.annotation.internalCommonAnnotationProcessor org.springframework.context.annotation.internalConfigurationAnnotationProcessor org.springframework.context.event.internalEventListenerFactory org.springframework.context.event.internalEventListenerProcessor parameterNamesModule preserveErrorControllerTargetClassPostProcessor propertySourcesPlaceholderConfigurer requestContextFilter requestMappingHandlerAdapter requestMappingHandlerMapping resourceHandlerMapping restTemplateBuilder routerFunctionMapping server-org.springframework.boot.autoconfigure.web.ServerProperties servletWebServerFactoryCustomizer simpleControllerHandlerAdapter spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties spring.jackson-org.springframework.boot.autoconfigure.jackson.JacksonProperties spring.lifecycle-org.springframework.boot.autoconfigure.context.LifecycleProperties spring.mvc-org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties spring.resources-org.springframework.boot.autoconfigure.web.ResourceProperties spring.servlet.multipart-org.springframework.boot.autoconfigure.web.servlet.MultipartProperties spring.task.execution-org.springframework.boot.autoconfigure.task.TaskExecutionProperties spring.task.scheduling-org.springframework.boot.autoconfigure.task.TaskSchedulingProperties standardJacksonObjectMapperBuilderCustomizer stringHttpMessageConverter taskExecutorBuilder taskSchedulerBuilder tomcatServletWebServerFactory tomcatServletWebServerFactoryCustomizer tomcatWebServerFactoryCustomizer viewControllerHandlerMapping viewResolver webServerFactoryCustomizerBeanPostProcessor websocketServletWebServerCustomizer welcomePageHandlerMapping </syntaxhighlight>我们可以发现,已经有了 dispatcherServlet 和 characterEncodingFilter
返回至
Spring Boot 自动配置特性
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
Spring Boot 2 零基础入门
Spring Cloud
Spring Boot
设计模式之禅
VUE
Vuex
Maven
算法
技能树
Wireshark
IntelliJ IDEA
ElasticSearch
VirtualBox
软考
正则表达式
程序员精讲
软件设计师精讲
初级程序员 历年真题
C
SQL
Java
FFmpeg
Redis
Kafka
MySQL
Spring
Docker
JMeter
Apache
Linux
Windows
Git
ZooKeeper
设计模式
Python
MyBatis
软件
数学
PHP
IntelliJ IDEA
CS基础知识
网络
项目
未分类
MediaWiki
镜像
问题
健身
国债
英语
烹饪
常见术语
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息