zoukankan      html  css  js  c++  java
  • 说说springboot启动机制 ----- maven对依赖的管理,场景器,SpringBootApplication,EnableAutoConfiguration几个注解,加载了Tomcat,Mvc ...

    说说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 ,启动验证

     








  • 相关阅读:
    集合(5)—Map之HashMap()
    《转》python 10 集合
    《转》python8元组
    《转》python(7)列表
    《转》python数据类型
    《转》python对象
    《转》python
    《转》python基础下
    《转》python学习基础
    《转》python 9 字典,numpy
  • 原文地址:https://www.cnblogs.com/rogge7/p/12986405.html
Copyright © 2011-2022 走看看