springboot备忘

springboot,alpha简称sb

预备——spring注解配置

@configuration

注解配置类,ConfigurationClassPostProcessor里解析其他注解,context:annotation-config/会注册在这个postProcessor.
用ConfigurationClassParser处理了@PropertySource, @ComponentScan, @Import, @ImportResource, @Bean.

@EnableAutoConfiguration

@Import(EnableAutoConfigurationImportSelector.class)
EnableAutoConfigurationImportSelector:使用SpringFactoriesLoader加载META-INF/spring.factories里的EnableAutoConfiguration对应的类。然后再用@AutoConfigureBefore和@AutoConfigueAfter排序
AutoConfiguration里面大部分是用@Conditional@configuration来注解注入相关组件

@ComponentScan
@PropertySource @PropertySources
@Import @ImportResource
@Conditional

在解析@Import和@Bean时用到

工作机制

@RestController

=> 这个不属于sb,乱入
=> @RestController加了@Controller,@ResponseBody注解
=> 在RequestResponseBodyMethodProcessor的supportsReturnType多加了判断方法所在class的注解是否注解了@ResponseBody

@SpringBootApplication

相当于
@Configuration:
@EnableAutoConfiguration:
@ComponentScan:

SpringApplication

将一个典型的Spring应用启动的流程“模版化”,并有很多扩展点来做特殊处理。和AbstractApplicationContext.refresh()一样各种准备和扩展点。

各种场景下的自动配置一站式插拔模块

来自SpringBoot揭秘
sb从两个主要层面影响Spring社区的开发者们:
1)基于Spring框架的“约定优先于配置(COC)”理念以及最佳实践之路;
2)提供了针对日常企业应用研发各种场景的spring-boot-starter自动配置依赖模块,如此之多“开箱即用”的依赖模块,使得开发各种场景的Spring应用更加快速和高效。

sb的行为可以进行干预的配置方式:优先级从高到低
1)命令行参数Command Line Args;
2)系统环境变量Environment Variables;
3)位于文件系统中的配置文件;
4)位于classpath中的配置文件;
5)固化到代码中的配置。

sb默认的配置文件是application.properties,在ConfigFileApplicationListener里加载和关联到spring容器里。

spring-boot-starter-loggin

sb的日志使用commons loggin,在org.springframework.boot.logging.LoggingApplicationListener里初始化的,并适配并初始化各种日志框架。 等级配置:logging.level.root=trace

spring-boot-starter-web

spring boot应用启动原理分析 http://blog.youkuaiyun.com/hengyunabc/article/details/50120001

学习参考

1)osc码云上的:http://git.oschina.net/didispace/SpringBoot-Learning
2)官方文档:http://docs.spring.io/spring-boot/docs/1.4.0.BUILD-SNAPSHOT/reference/htmlsingle/
3)《SpringBoot揭秘》
4)Spring Boot自动配置的
5) Spring Boot的自动化配置原理

转载于:https://my.oschina.net/braveCS/blog/738933

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值