first commit

This commit is contained in:
lisang 2024-06-27 21:35:52 +08:00
commit 0511ecebd8
1 changed files with 43 additions and 0 deletions

43
README.md Normal file
View File

@ -0,0 +1,43 @@
# 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.