shockkid-spring/README.md

43 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# SpringBoot需要知道的内容
> SpringBoot四大核心
- EnableAutoConfiguration 自动装配
- Start组件 开箱即用
- Actuator 监控
- SpringBoot Cli
> SpringBoot核心注解
- @SpringBootApplication 启动注解,组合注解
- @ComponentScan 扫描当前包和子包@Component注解修饰的类
- @SpringBootConfiguration 组合了configuration注解
- @EnableAutoConfiguration 打开自动装配功能 META-INF/spring.factories文件加载需要注入的Java类
---
## @EnableAutoConfiguration
Spring IoC加载Bean对象有四种配置方式
- xml通过<bean>标签
- java配置类 @Bean
- 扫描 @Component
- @Import开发层面比较少用,但是在框架层面用的比较多
## 面试题
### 1. Spring中的Bean是不是线程安全的
Spring中的Bean是从IOC中来的,IoC中的Bean从反射过来的, 反射读取配置文件得来的配置文件中的Bean是自己写的
自己写的Bean看情况不确定不好说不一定 跟spring无关只是IoC 控制权反转把new对象的控制权反转交给了Spring没有做任何策略
### 2. 自动配置的更改
Spring Boot 2.7.0对自动配置进行了不小的改动。
自动配置注册
现在Spring 自动配置类全限定名在META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. 中;而以前在 META-INF/spring.factories中。现在仍然向后兼容它们两个都会生效但是不推荐从spring.factories加载自动配置。
新的@AutoConfiguration 注解
引入了新的@AutoConfiguration注释。 这个类用于声明在上面自动配置注册中的AutoConfig类它替代了@Configuration只有自动配置类才能使用。你还可以通过其 after、afterNames、before、beforeNames 属性代替 @AutoConfigureAfter和@AutoConfigureBefore
### 3.