Comments (7)
SpringBootApplication注解是定义在spring-boot-autoconfigure模块中,通常被用作启动一个spring boot项目main方法所在类的注解。例如:
@SpringBootApplication public class SimpleMainTests { public static void main(String[] args) { SpringApplication.run(SimpleMainTests.class, new String[]{}); }}
from project.
该注解的官方说明
Indicates a configuration class that declares one or more @bean methods and also triggers auto-configuration and component scanning. This is a convenience annotation that is equivalent to declaring @configuration, @EnableAutoConfiguration and @componentscan.
指示一个Configuration类,该类声明一个或多个@bean方法,并触发EnableAutoConfiguration自动配置和ComponentScan组件扫描。其实就是一个复合注解,把@configuration、@EnableAutoConfiguration和@componentscan放在了一起。
from project.
看源码
@SpringBootConfiguration
@EnableAutoConfiguration
@componentscan(excludeFilters = {
@filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
from project.
@SpringBootConfiguration是@configuration的一种继承,在spring boot项目使用
from project.
@componentscan还是熟悉的味道,添加了2个custom的excludeFilter。其中TypeExcludeFilter主要是用在spring boot test中,不用关注。AutoConfigurationExcludeFilter是让自动配置的类不需要被ComponentScan扫描,它们有自己的注册方式。
from project.
@EnableAutoConfiguration 顾名思义就是用来启用spring boot的自动配置功能。
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @AutoConfigurationPackage @Import(AutoConfigurationImportSelector.class) public @interface EnableAutoConfiguration {
from project.
@EnableAutoConfiguration 其实就是引入了一个AutoConfigurationImportSelector类,从名称其实就可以看出它实现了ImportSelector,这接口的作用其实就是用来选择那些@configuration类被引入。but AutoConfigurationImportSelector 其实是实现了DeferredImportSelector接口,DeferredImportSelector是ImportSelector的一个变体,它是在所有的@configuration bean被处理完之后才运行的,主要是用来处理Conditional
from project.
Related Issues (19)
- Spring-BeanFactory解读 HOT 1
- Spring容器启动过程的源码分析 HOT 7
- BeanDefinitions加载流程 HOT 3
- 三种工厂模式 HOT 1
- Spring一个bean的初始化过程
- 【转载】【深入理解JVM】:Java内存模型JMM
- 设计模式之单例模式
- 一致性hash算法 HOT 1
- 缓存一致性协议
- Spring源码之AOP的实现方式 HOT 2
- 几种排序算法
- Spring的事务传播机制
- 数据的事务隔离级别 HOT 3
- 数据结构之树
- 分布式事务常用解决方案
- spring-boot2.X之AutoConfigurationImportSelector解析 HOT 8
- 编译openjdk10的过程 HOT 6
- 偏向锁的paper
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from project.