springboot 注解启动配置:
包自动扫描排除:
导入自动配置项:
通过类加载器扫描自动扫描元素属性:
Application.run()方法内部:
创建ApplicationContext后执行prepareContext我们都会发现
读取bean定义的工厂
之后的load方法
我们进去观察发现
Bean的生产加载
spring.factories的加载
按照约定大于配置的原则,starter启动必须要在META-INF下建立spring.factories文件
配置类的解析:
对配置文件进行解析
解析的注解依次有
解析下@ComponentScan通过ComponentScanAnnotationParser解析类进行解析
提供了parse()解析方法
ComponentScanPaser类parse解析方法提供的属性设置:
通过
提供的processConfigBeanDefinitions();方法
解析
配置了@Configuration的类
解析加载配置Bean
自动化配置实现:
对于@Value
值的替换
spring boot的注解有哪些:
1、@SpringBootApplication 这个注解包含了
@SpringBootConfiguration @EnableAutoConfiguration @ComponentScan
另外@EnableAutoConfiguration包含了
@AutoConfigurationPackage @Import
2、@Service 表示业务层
3、@Repository 表示DAO层
4、@RestController 是由@Controller和@ResponseBody组成
5、@RequestMapping 表示表示URL地址映射
6、@Component泛指组件,当组件不好归类的时候使用这个注解
7、@ComponentScan 表示扫描@Controller,@Service,@Repository,@Component的类,讲这些类注册,实例化bean
8、@Bean意思是产生一个Bean交给Spring管理
9、@EnableAutoConfiguration 是让Spring boot 应用根据所声明的依赖,对spring框架进行自动配置,一般放在主类上
10、@Autowire 通过byType的方式拿来用完成对方法属性的组装,他可以对类成员、方法、构造方法进行标注完成自动注入
11、@Qualifier和@Autowire经常配合使用
12、@RequestParam String a 相当于 String a = request.getParameter("a");