关于IOC容器源码分析
parent
a77cbbdf76
commit
e853162690
|
@ -33,8 +33,7 @@
|
|||
## 🌱Spring 源码阅读系列
|
||||
|
||||
+ IOC容器
|
||||
+ 关于IOC容器中获取Bean的过程源码分析
|
||||
|
||||
+ [关于IOC容器源码分析](spring-core-ioc/README.md)
|
||||
+ 后置处理器与初始化
|
||||
|
||||
+ [关于BeanFactoryPostProcessor源码分析](spring-interface-beanFactoryPostProcessor/README.md)
|
||||
|
@ -54,7 +53,6 @@
|
|||
+ [关于InitializingBean源码分析](spring-interface-initializingBean/README.md)
|
||||
|
||||
+ [关于DisposableBean源码分析](spring-interface-disposableBean/README.md)
|
||||
|
||||
+ 核心注解
|
||||
|
||||
+ 关于@Bean源码分析
|
||||
|
@ -62,7 +60,6 @@
|
|||
+ 关于@Configuration源码分析
|
||||
+ 关于@Import源码分析
|
||||
+ 关于@PropertySource源码分析
|
||||
|
||||
+ Bean生命周期和工厂
|
||||
|
||||
+ 关于BeanFactory源码分析
|
||||
|
@ -74,7 +71,6 @@
|
|||
+ 关于BeanDefinition源码分析
|
||||
+ 关于BeanDefinitionRegistry源码分析
|
||||
+ 关于FactoryBean源码分析
|
||||
|
||||
+ 应用上下文相
|
||||
|
||||
- 关于ApplicationContext源码分析
|
||||
|
@ -82,7 +78,6 @@
|
|||
- 关于WebApplicationContext源码分析
|
||||
- 关于ApplicationEventPublisher源码分析
|
||||
- 关于ApplicationListener源码分析
|
||||
|
||||
+ 环境变量
|
||||
|
||||
- 关于Environment源码分析
|
||||
|
|
1
pom.xml
1
pom.xml
|
@ -39,6 +39,7 @@
|
|||
<module>spring-interface-smartInstantiationAwareBeanPostProcessor</module>
|
||||
<module>spring-interface-initializingBean</module>
|
||||
<module>spring-interface-disposableBean</module>
|
||||
<module>spring-core-ioc</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>spring-reading</artifactId>
|
||||
<groupId>com.xcs.spring</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-core-ioc</artifactId>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,19 @@
|
|||
package com.xcs.spring;
|
||||
|
||||
import com.xcs.spring.config.MyConfiguration;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年09月16日 16时09分
|
||||
**/
|
||||
public class IOCApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MyConfiguration.class);
|
||||
for (String beanDefinitionName : context.getBeanDefinitionNames()) {
|
||||
System.out.println("Bean = " + context.getBean(beanDefinitionName));
|
||||
}
|
||||
context.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.xcs.spring.config;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年09月19日 16时35分
|
||||
**/
|
||||
@Configuration
|
||||
@ComponentScan("com.xcs.spring.service")
|
||||
public class MyConfiguration {
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.xcs.spring.service;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年09月21日 10时30分
|
||||
**/
|
||||
@Component
|
||||
public class MyServiceA {
|
||||
|
||||
public void destroy(){
|
||||
System.out.println("MyServiceA.destroy");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.xcs.spring.service;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author xcs
|
||||
* @date 2023年09月21日 10时30分
|
||||
**/
|
||||
@Component
|
||||
public class MyServiceB {
|
||||
|
||||
}
|
|
@ -62,7 +62,7 @@ public interface DestructionAwareBeanPostProcessor extends BeanPostProcessor {
|
|||
|
||||
### 三、主要功能
|
||||
|
||||
+ 销毁前逻辑:使用 `postProcessBeforeDestruction(Object bean, String beanName)` 方法,我们可以为 bean 执行自定义的销毁逻辑。当一个 bean 被容器标记为销毁时,此方法将被调用。(例如,容器关闭时进行资源释放,状态记录,依赖清理)
|
||||
+ **销毁前逻辑:**使用 `postProcessBeforeDestruction(Object bean, String beanName)` 方法,我们可以为 bean 执行自定义的销毁逻辑。当一个 bean 被容器标记为销毁时,此方法将被调用。(例如,容器关闭时进行资源释放,状态记录,依赖清理)
|
||||
|
||||
### 四、最佳实践
|
||||
|
||||
|
|
Loading…
Reference in New Issue