@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 {
- @SpringBootApplication
- @SpringBootConfiguration
- @Configuration
- @Component
spring boot东西基本都是spring早就存在的(2.5版本出现,2.0之前的文档未检索到),下面是spring的功能
@ComponentScan: 它是 Spring Framework 3.1引入的
@EnableAutoConfiguration: 激活自动装配 @Enable -> @Enable 开头的
@EnableWebMvc
@EnableTransactionManagement ....
@SpringBootConfiguration : 等价于 @Configuration
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration
public @interface SpringBootConfiguration {
Spring 注解编程模型
注解不可以继承,那么可以说@Service、@Controller是@Component的变种、衍生吧。具有@Component特性。
Spring 注解驱动
注解驱动上下文 AnnotationConfigApplicationContext , Spring Framework 3.0 开始引入的
示例:
使用spring boot配置信息的时候,常用application.properties,那肯定有代码配置的地方。示例为获取随机可以端口,用于单元测试。
源码跟踪到SpringApplication#configurePropertySources中
SpringApplicationBuilder引导
设置非web应用
当不加以设置 Web 类型,开始推断:SpringAppliation() -> deduceWebApplicationType() 第一次推断为 WebApplicationType.SERVLET,然后直接到run方法时会获取是否设置了WebApplicationType,如果设置就使用当前设置的类型。
判断的优先级
WebApplicationType.REACTIVE : Spring WebFlux
DispatcherHandler 、webflux 存在 Servlet、web 不存在
WebApplicationType.NONE : 非 Web 类型
Servlet、ConfigurableWebApplicationContext、web、webflux 不存在
WebApplicationType.SERVLET : Spring MVC
web 存在