forked from coderbruis/JavaSourceCodeLearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyAwareProcessor.java
More file actions
36 lines (28 loc) · 1.05 KB
/
MyAwareProcessor.java
File metadata and controls
36 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.bruis.learnsb.aware;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.Aware;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;
/**
*
* 自定义实现的aware处理器
*
* @author LuoHaiYang
*/
@Component
public class MyAwareProcessor implements BeanPostProcessor {
private final ConfigurableApplicationContext configurableApplicationContext;
public MyAwareProcessor(ConfigurableApplicationContext configurableApplicationContext) {
this.configurableApplicationContext = configurableApplicationContext;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof Aware) {
if (bean instanceof MyAware) {
((MyAware) bean).setFlag((Flag) configurableApplicationContext.getBean("flag"));
}
}
return bean;
}
}