说说springboot启动机制
Posted 是蓝蓝的呀
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了说说springboot启动机制相关的知识,希望对你有一定的参考价值。
说说springboot启动机制
https://ke.qq.com/webcourse/index.html#cid=333216&term_id=100395479&taid=2568313133929888&vid=5285890788262993749
通过@EnableAutoConfiguration 加载
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootConfiguration @EnableAutoConfiguration ---> @ComponentScan( excludeFilters = {@Filter( type = FilterType.CUSTOM, classes = {TypeExcludeFilter.class} ), @Filter( type = FilterType.CUSTOM, classes = {AutoConfigurationExcludeFilter.class} )} ) public @interface SpringBootApplication { @AliasFor(
@Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @AutoConfigurationPackage @Import({EnableAutoConfigurationImportSelector.class}) //------>通过 public @interface EnableAutoConfiguration { String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration"; Class<?>[] exclude() default {}; String[] excludeName() default {}; }
@Import 把一个类通过这种方式交给Spring容器管理
@Import({EnableAutoConfigurationImportSelector.class}) 点进去看这个类,再看它的父类
@Deprecated
public class EnableAutoConfigurationImportSelector extends AutoConfigurationImportSelector {
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) { List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader()); Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct."); return configurations; }
看出它回到这个包的路径下读取这个spring.factories配置文件:重点看这个三个
org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration这个文件中,有启动Tomcat
老师的版本是2.0
本人这个org.springframework.boot.autoconfigure 的jar包是1.5.10... 启动tomcat如下代码
WebMvcAutoConfiguration.java 文件中:主要通过enablewebmvc注解 把springmvc加载进来
手写spirngboot ,启动验证
以上是关于说说springboot启动机制的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“(代码片段
全栈编程系列SpringBoot整合Shiro(含KickoutSessionControlFilter并发在线人数控制以及不生效问题配置启动异常No SecurityManager...)(代码片段