标签:功能 xxx xml文件 exclude stat tor tomcat Servle and
Spring Boot核心原理
spring-boot-starter-xxx 方便开发和配置
1、没有depoy setup tomcat
2、xml文件里面的没有没有了
@SpringBootApplication //注解
public class Springbootdemo1Application {
public static void main(String[] args) {
//严格意义上执行的是这块代码
SpringApplication.run(Springbootdemo1Application.class, args);
}
}
一、 SpringBootApplication注解
注解的功能:参考https://docs.spring.io/spring-boot/docs/2.1.5.RELEASE/reference/htmlsingle/#boot-documentation
除了元注解,还有三个注解
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan( excludeFilters =
{@Filter(
type = FilterType.CUSTOM,
classes = {TypeExcludeFilter.class}
), @Filter(
type = FilterType.CUSTOM,
classes = {AutoConfigurationExcludeFilter.class}
)}
@SpringBootConfiguration 注解

让我们当前的Bean叫给Spring容器进行管理(IOC),让当前类变成配置类,不需要XML文件进行配置(配置类)。
EnableAutoConfiguration注解

@AutoConfigurationPackage
让包中的类以及子包中的类能被自动扫描到Spring 容器中
@Import({AutoConfigurationImportSelector.class})
程序中默认使用的类帮我们找到
AutoConfigurationImportSelector类如下: 里面的selectImports里面,调用了getAutoConfigurationEntry方法。

getAutoConfigurationEntry方法中调用getCandidateConfigurations方法

getCandidateConfigurations方法使用的文件在META-INF/spring.factories

META-INF/spring.factories保存了系统默认加载进来的类。
这个文件的路径如下图:

@ComponentScan注解
通常它会结合@Coponent相关东西进行使用
总结:@SpringBootApplication
结合Spring MVC:
系统可能用到的Bean,帮我们放在了spring.factories 文件夹中
自己需要加载的bean, @Component结合@ComponentScan
二、 SpringApplication.run(Springbootdemo1Application.class, args);
程序启动的时候执行这段代码,
1、寻找内置的Tomcat执行的地方
this.refreshContext(context);
this.refresh(context);
((AbstractApplicationContext)applicationContext).refresh();
this.onRefresh()
onRefresh(ServletWebServerApplicationContext类中)
this.createWebServer();
factory.getWebServer
最终找到内置创建Tomcat的方法

2、@SpringBootApplication注解:在spring.factories准备的类不一定会用到
SpringApplication.run(Springbootdemo1Application.class, args): 拿到准备类中的文件--> 具体创建对象
如下图创建Tomcat实例


标签:功能 xxx xml文件 exclude stat tor tomcat Servle and
原文地址:https://www.cnblogs.com/linlf03/p/10853465.html