Maven: org.springframework:spring-beans
org.springframeworkspring.beans.factory
接口BeanFactory
spring bean容器的顶级接口
接口InitializingBean
bean实现该接口,会在创建完成后执行afterPropertiesSet()
接口DisposableBean
bean实现该接口,会在销毁执行destroy()
org.springframeworkspring.beans.factory.annotation
注解Autowired
自动注入
org.springframework.beans.factory.config
接口BeanDefinition
Bean定义信息
接口BeanFactoryPostProcessor
BeanFactory后置处理器
接口BeanPostProcessor
Bean后置处理器
- postProcessBeforeInitialization()
- postProcessAfterInitialization()
类PropertyOverrideConfigurer
通过读取自定义的配置文件来覆盖bean definition中的属性值(工作模式: “推”)
Maven: org.springframework:spring-context
org.springframework.context
接口ApplicationContextAware
org.springframework.context.annotation
注解Bean
org.springframework.context.support
类PropertySourcesPlaceholderConfigurer
替换bean definition中的${…}为配置文件中的真实值(工作模式: “拉”)
org.springframework.stereotype
注解Component
注解Controller
注解Repository
注解Service
Maven: org.springframework:spring-core
org.springframework.core
接口Ordered
表示排序的接口,值越小优先级越高
接口PriorityOrdered
继承自
Ordered接口,当PriorityOrdered与纯Ordered一起排序时,PriorityOrdered的优先级总是比Ordered更高(无视其order value)
org.springframework.util
抽象类FileCopyUtils
Stream工具类,会手动关闭流
抽象类StreamUtils
Stream工具类,不会关闭流
抽象类StringUtils
String工具类
LIFECYCLE CALLBACK
| - | 硬编码(官方不推荐) | 注解 | xml |
|---|---|---|---|
| 初始化后 | 类实现InitializingBean接口 |
@BEAN注解中的initMethod属性(Spring)或方法添加注解@PostConstruct(JSR-250) |
init-method属性 |
| 销毁前 | 类实现DisposableBean接口 |
@BEAN注解中的destroyMethod属性(Spring)或方法添加注解@PreDestroy(JSR-250) |
destroy-method属性 |