spring源码分析——BeanPostProcessor接口

BeanPostProcessor是处理bean的后置接口,beanDefinitionMaps中的BeanDefinition实例化完成后,完成populateBean,属性设置,完成

初始化后,这个接口支持对bean做自定义的操作。

一:BeanPostProcessor的使用

定义一个测试用的model对象,name属性默认为hello

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class BeanDemo {

private String name = "hello";

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Override
public String toString() {
    final StringBuffer sb = new StringBuffer("BeanDemo{");
    sb.append("name='").append(name).append('\'');
    sb.append('}');
    return sb.toString();
}

}

自定义一个MyBeanPostProcessor类,实现BeanPostProcessor接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Service
public class MyBeanPostProcessor implements BeanPostProcessor {

public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    return null;
}

public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if(beanName.equals("beanDemo")){
        BeanDemo beanDemo = (BeanDemo)bean;
        beanDemo.setName("kitty");
        return beanDemo;
    }
    return bean;
}

}

从运行结果看,spring中维护的beanName为beanDemo的对象,name属性为ketty

二:看看源码怎么实现的

1:实例化并且注册到beanPostProcessors集合中

主要的实例化逻辑在这个接口,这个接口的作用就是把所有实现BeanPostProcessor接口的类实例化,然后注册到 beanPostProcessors这个缓存中
一:BeanDefinitionRegistryPostProcessor 与BeanFactoryPostProcessor接口

这个接口支持自定义beanDefinition的注册,在标准的注册完成后(解析xml或者注解),在与实例化对象之前,实现这个接口

可以向beanDefinitionMap中注册自定义的beanDefinition,这个接口从定义上看更多的是关注注册。

1:实现beanDefinitionRegistryPostProcessor接口,重写postProcessBeanDefinitionRegistry方法,在方法内创建beanDefinition对象,然后注册到beanDefinitionRegistry中

创建一个pojo对象BeanDemo,用于测试在接口中注册自定义beanDefinition

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class BeanDemo {

private String name = "hello";

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Override
public String toString() {
    final StringBuffer sb = new StringBuffer("BeanDemo{");
    sb.append("name='").append(name).append('\'');
    sb.append('}');
    return sb.toString();
}

}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Component
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {

public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
    System.out.println("MyBeanDefinitionRegistryPostProcessor: "+registry);

    // 向beanDefinitionMap中注册自定义的beanDefinition对象
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(BeanDemo.class);
    registry.registerBeanDefinition("beanDemo",beanDefinition);
}

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    System.out.println("MyBeanDefinitionRegistryPostProcessor: "+beanFactory);
}

}

成功的从spring容器中拿到了对象:

2:BeanFactoryPostProcessor接口

这个接口支持修改容器内的beanDefinition对象,也可以直接注册bean对象,在标准的beanDefinition注册之后以及预实例化bean对象之前

通过运行结果可以看出beanDefinition在postProcessBeanFactory方法中被修改:

在beanFactoryPostProcessor接口中注册对象后,可以在spring中获取到。

二:从源码层面分析接口调用

refresh方法中invokeBeanFactoryPostProcessors:

主要的核心逻辑都在这个方法内:

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
public static void invokeBeanFactoryPostProcessors(
ConfigurableListableBeanFactory beanFactory, List beanFactoryPostProcessors) {

    // Invoke BeanDefinitionRegistryPostProcessors first, if any.
    // 如果存在BeanDefinitionRegistryPostProcessor类型对象,要先调用
    Set processedBeans = new HashSet<>();

    if (beanFactory instanceof BeanDefinitionRegistry) {
        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        List regularPostProcessors = new ArrayList<>();
        List registryProcessors = new ArrayList<>();

        // 第一次进来beanFactoryPostProcessors集合为空,不会走进来
        for (BeanFactoryPostProcessor postProcessor : beanFactoryPostProcessors) {
            if (postProcessor instanceof BeanDefinitionRegistryPostProcessor) {
                BeanDefinitionRegistryPostProcessor registryProcessor =
                        (BeanDefinitionRegistryPostProcessor) postProcessor;
                registryProcessor.postProcessBeanDefinitionRegistry(registry);
                registryProcessors.add(registryProcessor);
            }
            else {
                regularPostProcessors.add(postProcessor);
            }
        }

        // Do not initialize FactoryBeans here: We need to leave all regular beans
        // uninitialized to let the bean factory post-processors apply to them!
        // Separate between BeanDefinitionRegistryPostProcessors that implement
        // PriorityOrdered, Ordered, and the rest.
        /**
         * 不要在这里初始化FactoryBean类型的对象,不要初始化post-Processor对象,要把
         * PriorityOrdered类型和Ordered类型以及剩下的分开
         */
        List currentRegistryProcessors = new ArrayList<>();

        // First, invoke the BeanDefinitionRegistryPostProcessors that implement PriorityOrdered.
        /**
         * 1: 根据类型找到所有实现BeanDefinitionRegistryPostProcessor接口的beanName
         * 2: 遍历所有beanName,判断是否是PriorityOrdered接口的实例
         * 3: 如果是则 getBean实例化这个对象,然后放入processedBean集合中
         *
         * 在这里getBeanNamesForType 会把字父类的beanDefinition合并Merge,得到RootBeanDefinition
         */
        String[] postProcessorNames =
                beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false);
        for (String ppName : postProcessorNames) {
            if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
                currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
                processedBeans.add(ppName);
            }
        }

        /**
         * 1:对currentRegistryProcessors集合内实例对象排序
         * 2: 将排序过的集合添加到注册集合registryProcessors中
         * 3:调用currentRegistryProcessors集合中对象方法
         * 4:清空当前注册对象集合currentRegistryProcessors
         */
        sortPostProcessors(currentRegistryProcessors, beanFactory);
        registryProcessors.addAll(currentRegistryProcessors);
        // 调用注册对象方法
        invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
        currentRegistryProcessors.clear();

        // Next, invoke the BeanDefinitionRegistryPostProcessors that implement Ordered.
        /**
         * 在这里步骤和上一步类似,只不过这里操作的是实现Ordered接口的类
         */
        postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false);
        for (String ppName : postProcessorNames) {
            if (!processedBeans.contains(ppName) && beanFactory.isTypeMatch(ppName, Ordered.class)) {
                currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
                processedBeans.add(ppName);
            }
        }
        sortPostProcessors(currentRegistryProcessors, beanFactory);
        registryProcessors.addAll(currentRegistryProcessors);
        invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
        currentRegistryProcessors.clear();

        // Finally, invoke all other BeanDefinitionRegistryPostProcessors until no further ones appear.
        /**
         * 还是重复上面的动作,不过这次是排除掉上面已经调用过的实例(实现PriorityOrdered和Ordered接口)
         */
        boolean reiterate = true;
        while (reiterate) {
            reiterate = false;
            postProcessorNames = beanFactory.getBeanNamesForType(BeanDefinitionRegistryPostProcessor.class, true, false);
            for (String ppName : postProcessorNames) {
                if (!processedBeans.contains(ppName)) {
                    currentRegistryProcessors.add(beanFactory.getBean(ppName, BeanDefinitionRegistryPostProcessor.class));
                    processedBeans.add(ppName);
                    reiterate = true;
                }
            }
            sortPostProcessors(currentRegistryProcessors, beanFactory);
            registryProcessors.addAll(currentRegistryProcessors);
            invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry);
            currentRegistryProcessors.clear();
        }

        // Now, invoke the postProcessBeanFactory callback of all processors handled so far.
        /**
         * 在这里,调用上面已经处理过的所有处理器的postProcessBeanFactory回调方法
         */
        invokeBeanFactoryPostProcessors(registryProcessors, beanFactory);
        invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory);
    }

    else {
        // Invoke factory processors registered with the context instance.
        invokeBeanFactoryPostProcessors(beanFactoryPostProcessors, beanFactory);
    }

    // Do not initialize FactoryBeans here: We need to leave all regular beans
    // uninitialized to let the bean factory post-processors apply to them!
    String[] postProcessorNames =
            beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, true, false);

    // Separate between BeanFactoryPostProcessors that implement PriorityOrdered,
    // Ordered, and the rest.
    List priorityOrderedPostProcessors = new ArrayList<>();
    List orderedPostProcessorNames = new ArrayList<>();
    List nonOrderedPostProcessorNames = new ArrayList<>();
    for (String ppName : postProcessorNames) {
        if (processedBeans.contains(ppName)) {
            // skip - already processed in first phase above
        }
        else if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
            priorityOrderedPostProcessors.add(beanFactory.getBean(ppName, BeanFactoryPostProcessor.class));
        }
        else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
            orderedPostProcessorNames.add(ppName);
        }
        else {
            nonOrderedPostProcessorNames.add(ppName);
        }
    }

    // First, invoke the BeanFactoryPostProcessors that implement PriorityOrdered.
    sortPostProcessors(priorityOrderedPostProcessors, beanFactory);
    invokeBeanFactoryPostProcessors(priorityOrderedPostProcessors, beanFactory);

    // Next, invoke the BeanFactoryPostProcessors that implement Ordered.
    List orderedPostProcessors = new ArrayList<>();
    for (String postProcessorName : orderedPostProcessorNames) {
        orderedPostProcessors.add(beanFactory.getBean(postProcessorName, BeanFactoryPostProcessor.class));
    }
    sortPostProcessors(orderedPostProcessors, beanFactory);
    invokeBeanFactoryPostProcessors(orderedPostProcessors, beanFactory);

    // Finally, invoke all other BeanFactoryPostProcessors.
    List nonOrderedPostProcessors = new ArrayList<>();
    for (String postProcessorName : nonOrderedPostProcessorNames) {
        nonOrderedPostProcessors.add(beanFactory.getBean(postProcessorName, BeanFactoryPostProcessor.class));
    }
    invokeBeanFactoryPostProcessors(nonOrderedPostProcessors, beanFactory);

    // Clear cached merged bean definitions since the post-processors might have
    // modified the original metadata, e.g. replacing placeholders in values...
    beanFactory.clearMetadataCache();

https://www.birdnet.cn/thread-4679022-1-2.html
https://www.birdnet.cn/thread-4679022-1-1.html
https://www.birdnet.cn/thread-4679022-1-7.html
https://www.birdnet.cn/thread-4679022-1-3.html
https://www.birdnet.cn/thread-4679021-1-2.html
https://www.birdnet.cn/thread-4679021-1-1.html
https://www.birdnet.cn/thread-4679021-1-7.html
https://www.birdnet.cn/thread-4679021-1-3.html
https://www.birdnet.cn/thread-4679020-1-2.html
https://www.birdnet.cn/thread-4679020-1-1.html
https://www.birdnet.cn/thread-4679020-1-8.html
https://www.birdnet.cn/thread-4679020-1-3.html
https://www.birdnet.cn/thread-4679019-1-2.html
https://www.birdnet.cn/thread-4679019-1-1.html
https://www.birdnet.cn/thread-4679019-1-1.html
https://www.birdnet.cn/thread-4679019-1-3.html
https://www.birdnet.cn/thread-4679016-1-2.html
https://www.birdnet.cn/thread-4679016-1-1.html
https://www.birdnet.cn/thread-4679016-1-3.html
https://www.birdnet.cn/thread-4679016-1-3.html
https://www.birdnet.cn/thread-4679015-1-2.html
https://www.birdnet.cn/thread-4679015-1-1.html
https://www.birdnet.cn/thread-4679015-1-6.html
https://www.birdnet.cn/thread-4679015-1-3.html
https://www.birdnet.cn/thread-4679014-1-2.html
https://www.birdnet.cn/thread-4679014-1-1.html
https://www.birdnet.cn/thread-4679014-1-3.html
https://www.birdnet.cn/thread-4679014-1-3.html
https://www.birdnet.cn/thread-4679013-1-2.html
https://www.birdnet.cn/thread-4679013-1-1.html
https://www.birdnet.cn/thread-4679013-1-7.html
https://www.birdnet.cn/thread-4679013-1-3.html
https://www.birdnet.cn/thread-4679012-1-2.html
https://www.birdnet.cn/thread-4679012-1-1.html
https://www.birdnet.cn/thread-4679012-1-2.html
https://www.birdnet.cn/thread-4679012-1-3.html
https://www.birdnet.cn/thread-4679011-1-2.html
https://www.birdnet.cn/thread-4679011-1-1.html
https://www.birdnet.cn/thread-4679011-1-2.html
https://www.birdnet.cn/thread-4679011-1-3.html
https://www.birdnet.cn/thread-4679010-1-2.html
https://www.birdnet.cn/thread-4679010-1-1.html
https://www.birdnet.cn/thread-4679010-1-7.html
https://www.birdnet.cn/thread-4679010-1-3.html
https://www.birdnet.cn/thread-4679009-1-2.html
https://www.birdnet.cn/thread-4679009-1-1.html
https://www.birdnet.cn/thread-4679009-1-5.html
https://www.birdnet.cn/thread-4679009-1-3.html
https://www.birdnet.cn/thread-4679008-1-2.html
https://www.birdnet.cn/thread-4679008-1-1.html
https://www.birdnet.cn/thread-4679008-1-3.html
https://www.birdnet.cn/thread-4679008-1-3.html
https://www.birdnet.cn/thread-4679007-1-2.html
https://www.birdnet.cn/thread-4679007-1-1.html
https://www.birdnet.cn/thread-4679007-1-8.html
https://www.birdnet.cn/thread-4679007-1-3.html
https://www.birdnet.cn/thread-4679006-1-2.html
https://www.birdnet.cn/thread-4679006-1-1.html
https://www.birdnet.cn/thread-4679006-1-1.html
https://www.birdnet.cn/thread-4679006-1-3.html
https://www.birdnet.cn/thread-4679005-1-2.html
https://www.birdnet.cn/thread-4679005-1-1.html
https://www.birdnet.cn/thread-4679005-1-2.html
https://www.birdnet.cn/thread-4679005-1-3.html
https://www.birdnet.cn/thread-4679004-1-2.html
https://www.birdnet.cn/thread-4679004-1-1.html
https://www.birdnet.cn/thread-4679004-1-5.html
https://www.birdnet.cn/thread-4679004-1-3.html
https://www.birdnet.cn/thread-4679003-1-2.html
https://www.birdnet.cn/thread-4679003-1-1.html
https://www.birdnet.cn/thread-4679003-1-6.html
https://www.birdnet.cn/thread-4679003-1-3.html
https://www.birdnet.cn/thread-4679001-1-2.html
https://www.birdnet.cn/thread-4679001-1-1.html
https://www.birdnet.cn/thread-4679001-1-6.html
https://www.birdnet.cn/thread-4679001-1-3.html
https://www.birdnet.cn/thread-4678999-1-2.html
https://www.birdnet.cn/thread-4678999-1-1.html
https://www.birdnet.cn/thread-4678999-1-6.html
https://www.birdnet.cn/thread-4678999-1-3.html
https://www.birdnet.cn/thread-4678988-1-2.html
https://www.birdnet.cn/thread-4678988-1-1.html
https://www.birdnet.cn/thread-4678988-1-7.html
https://www.birdnet.cn/thread-4678988-1-3.html
https://www.birdnet.cn/thread-4678986-1-2.html
https://www.birdnet.cn/thread-4678986-1-1.html
https://www.birdnet.cn/thread-4678986-1-0.html
https://www.birdnet.cn/thread-4678986-1-3.html
https://www.birdnet.cn/thread-4678984-1-2.html
https://www.birdnet.cn/thread-4678984-1-1.html
https://www.birdnet.cn/thread-4678984-1-7.html
https://www.birdnet.cn/thread-4678984-1-3.html
https://www.birdnet.cn/thread-4678982-1-2.html
https://www.birdnet.cn/thread-4678982-1-1.html
https://www.birdnet.cn/thread-4678982-1-5.html
https://www.birdnet.cn/thread-4678982-1-3.html
https://www.birdnet.cn/thread-4678980-1-2.html
https://www.birdnet.cn/thread-4678980-1-1.html
https://www.birdnet.cn/thread-4678980-1-8.html
https://www.birdnet.cn/thread-4678980-1-3.html
https://www.birdnet.cn/thread-4678920-1-2.html
https://www.birdnet.cn/thread-4678920-1-1.html
https://www.birdnet.cn/thread-4678919-1-2.html
https://www.birdnet.cn/thread-4678919-1-1.html
https://www.birdnet.cn/thread-4678917-1-2.html
https://www.birdnet.cn/thread-4678917-1-1.html
https://www.birdnet.cn/thread-4678916-1-2.html
https://www.birdnet.cn/thread-4678916-1-1.html
https://www.birdnet.cn/thread-4678909-1-2.html
https://www.birdnet.cn/thread-4678909-1-1.html
https://www.birdnet.cn/thread-4678907-1-2.html
https://www.birdnet.cn/thread-4678907-1-1.html
https://www.birdnet.cn/thread-4678906-1-2.html
https://www.birdnet.cn/thread-4678906-1-1.html
https://www.birdnet.cn/thread-4678903-1-2.html
https://www.birdnet.cn/thread-4678903-1-1.html
https://www.birdnet.cn/thread-4678898-1-2.html
https://www.birdnet.cn/thread-4678898-1-1.html
https://www.birdnet.cn/thread-4678897-1-2.html
https://www.birdnet.cn/thread-4678897-1-1.html
https://www.birdnet.cn/thread-4678896-1-2.html
https://www.birdnet.cn/thread-4678896-1-1.html
https://www.birdnet.cn/thread-4678894-1-2.html
https://www.birdnet.cn/thread-4678894-1-1.html
https://www.birdnet.cn/thread-4678893-1-2.html
https://www.birdnet.cn/thread-4678893-1-1.html
https://www.birdnet.cn/thread-4678891-1-2.html
https://www.birdnet.cn/thread-4678891-1-1.html
https://www.birdnet.cn/thread-4678889-1-2.html
https://www.birdnet.cn/thread-4678889-1-1.html
https://www.birdnet.cn/thread-4678888-1-2.html
https://www.birdnet.cn/thread-4678888-1-1.html
https://www.birdnet.cn/thread-4678887-1-2.html
https://www.birdnet.cn/thread-4678887-1-1.html
https://www.birdnet.cn/thread-4678885-1-2.html
https://www.birdnet.cn/thread-4678885-1-1.html
https://www.birdnet.cn/thread-4678884-1-2.html
https://www.birdnet.cn/thread-4678884-1-1.html
https://www.birdnet.cn/thread-4678854-1-2.html
https://www.birdnet.cn/thread-4678854-1-1.html
https://www.birdnet.cn/thread-4678853-1-2.html
https://www.birdnet.cn/thread-4678853-1-1.html
https://www.birdnet.cn/thread-4678851-1-2.html
https://www.birdnet.cn/thread-4678851-1-1.html
https://www.birdnet.cn/thread-4678849-1-2.html
https://www.birdnet.cn/thread-4678849-1-1.html
https://www.birdnet.cn/thread-4678847-1-2.html
https://www.birdnet.cn/thread-4678847-1-1.html
https://www.birdnet.cn/thread-4678793-1-2.html
https://www.birdnet.cn/thread-4678793-1-1.html
https://www.birdnet.cn/thread-4678792-1-2.html
https://www.birdnet.cn/thread-4678792-1-1.html
https://www.birdnet.cn/thread-4678791-1-2.html
https://www.birdnet.cn/thread-4678791-1-1.html
https://www.birdnet.cn/thread-4678790-1-2.html
https://www.birdnet.cn/thread-4678790-1-1.html
https://www.birdnet.cn/thread-4678789-1-2.html
https://www.birdnet.cn/thread-4678789-1-1.html
https://www.birdnet.cn/thread-4678788-1-2.html
https://www.birdnet.cn/thread-4678788-1-1.html
https://www.birdnet.cn/thread-4678787-1-2.html
https://www.birdnet.cn/thread-4678787-1-1.html
https://www.birdnet.cn/thread-4678786-1-2.html
https://www.birdnet.cn/thread-4678786-1-1.html
https://www.birdnet.cn/thread-4678785-1-2.html
https://www.birdnet.cn/thread-4678785-1-1.html
https://www.birdnet.cn/thread-4678783-1-2.html
https://www.birdnet.cn/thread-4678783-1-1.html
https://www.birdnet.cn/thread-4678782-1-2.html
https://www.birdnet.cn/thread-4678782-1-1.html
https://www.birdnet.cn/thread-4678781-1-2.html
https://www.birdnet.cn/thread-4678781-1-1.html
https://www.birdnet.cn/thread-4678779-1-2.html
https://www.birdnet.cn/thread-4678779-1-1.html
https://www.birdnet.cn/thread-4678778-1-2.html
https://www.birdnet.cn/thread-4678778-1-1.html
https://www.birdnet.cn/thread-4678777-1-2.html
https://www.birdnet.cn/thread-4678777-1-1.html
https://www.birdnet.cn/thread-4678776-1-2.html
https://www.birdnet.cn/thread-4678776-1-1.html
https://www.birdnet.cn/thread-4678775-1-2.html
https://www.birdnet.cn/thread-4678775-1-1.html
https://www.birdnet.cn/thread-4678774-1-2.html
https://www.birdnet.cn/thread-4678774-1-1.html
https://www.birdnet.cn/thread-4678772-1-2.html
https://www.birdnet.cn/thread-4678772-1-1.html
https://www.birdnet.cn/thread-4678771-1-2.html
https://www.birdnet.cn/thread-4678771-1-1.html
https://www.birdnet.cn/thread-4678737-1-2.html
https://www.birdnet.cn/thread-4678737-1-1.html
https://www.birdnet.cn/thread-4678736-1-2.html
https://www.birdnet.cn/thread-4678736-1-1.html
https://www.birdnet.cn/thread-4678735-1-2.html
https://www.birdnet.cn/thread-4678735-1-1.html
https://www.birdnet.cn/thread-4678734-1-2.html
https://www.birdnet.cn/thread-4678734-1-1.html
https://www.birdnet.cn/thread-4678733-1-2.html
https://www.birdnet.cn/thread-4678733-1-1.html

public static void registerBeanPostProcessors(
ConfigurableListableBeanFactory beanFactory, AbstractApplicationContext applicationContext) {

// 获取所有实现接口BeanPostProcessor的beanName
String[] postProcessorNames = beanFactory.getBeanNamesForType(BeanPostProcessor.class, true, false);

// Register BeanPostProcessorChecker that logs an info message when
// a bean is created during BeanPostProcessor instantiation, i.e. when
// a bean is not eligible for getting processed by all BeanPostProcessors.
int beanProcessorTargetCount = beanFactory.getBeanPostProcessorCount() + 1 + postProcessorNames.length;
beanFactory.addBeanPostProcessor(new BeanPostProcessorChecker(beanFactory, beanProcessorTargetCount));

// Separate between BeanPostProcessors that implement PriorityOrdered,
// Ordered, and the rest.
/**
 * 把实现PriorityOrdered 和 Ordered 和 其他的处理器分开
 */
List priorityOrderedPostProcessors = new ArrayList<>();
List internalPostProcessors = new ArrayList<>();
List orderedPostProcessorNames = new ArrayList<>();
List nonOrderedPostProcessorNames = new ArrayList<>();
/**
 * 1:遍历集合postProcessorNames
 * 2:判断类型,如果是PriorityOrdered,则实例化对象放入priorityOrderedPostProcessors集合,
 * Ordered 则放入orderedPostProcessorNames集合,其他的放入nonOrderedPostProcessorNames集合
 */
for (String ppName : postProcessorNames) {
    if (beanFactory.isTypeMatch(ppName, PriorityOrdered.class)) {
        BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
        priorityOrderedPostProcessors.add(pp);
        if (pp instanceof MergedBeanDefinitionPostProcessor) {
            internalPostProcessors.add(pp);
        }
    }
    else if (beanFactory.isTypeMatch(ppName, Ordered.class)) {
        orderedPostProcessorNames.add(ppName);
    }
    else {
        nonOrderedPostProcessorNames.add(ppName);
    }
}

// First, register the BeanPostProcessors that implement PriorityOrdered.
// 首先对priorityOrderedPostProcessors集合中实例对象排序,然后注册,放入beanFactory中缓存下来
sortPostProcessors(priorityOrderedPostProcessors, beanFactory);
registerBeanPostProcessors(beanFactory, priorityOrderedPostProcessors);

// Next, register the BeanPostProcessors that implement Ordered.
// 然后再实例化实现Ordered接口的对象,完成注册
List orderedPostProcessors = new ArrayList<>();
for (String ppName : orderedPostProcessorNames) {
    BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
    orderedPostProcessors.add(pp);
    if (pp instanceof MergedBeanDefinitionPostProcessor) {
        internalPostProcessors.add(pp);
    }
}
sortPostProcessors(orderedPostProcessors, beanFactory);
registerBeanPostProcessors(beanFactory, orderedPostProcessors);

// Now, register all regular BeanPostProcessors.
// 最后实例化什么都没有实现的,完成实例化并注册
List nonOrderedPostProcessors = new ArrayList<>();
for (String ppName : nonOrderedPostProcessorNames) {
    BeanPostProcessor pp = beanFactory.getBean(ppName, BeanPostProcessor.class);
    nonOrderedPostProcessors.add(pp);
    if (pp instanceof MergedBeanDefinitionPostProcessor) {
        internalPostProcessors.add(pp);
    }
}
registerBeanPostProcessors(beanFactory, nonOrderedPostProcessors);

// Finally, re-register all internal BeanPostProcessors.
// 最后再次注册内部postProcessor
sortPostProcessors(internalPostProcessors, beanFactory);
registerBeanPostProcessors(beanFactory, internalPostProcessors);

// Re-register post-processor for detecting inner beans as ApplicationListeners,
// moving it to the end of the processor chain (for picking up proxies etc).
beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(applicationContext));

}

定义四类容器,高优先级有序、有序、无序、内部

分类放入四种容器:

注册BeanPostProcessor,将实现BeanPostProcessor接口的对象放入beanPostProcessors缓存中

注册完PriorityOrdered的实现类后,再处理Ordered的实现类

注册什么都没有实现的BeanPostProcessor接口实现类,

最后注册内部的BeanPostProcessor对象

到这里BeanPostProcessor的实例化以及注册工作完成,在beanFactory的beanPostProcessors集合中已经缓存了所有的beanPostProcessor的对象

2:BeanPostProcessor的使用

因为这个接口是bean的后置接口,所以需要bean创建并初始化完成,才可以发挥作用,上一步的缓存只是埋好点,以备使用,因为bean的实例化流程我们

还没有分析,这里直接看一下怎么使用的

我们看一下init方法后的拦截,因为这个时候已经init完成,可以在后置接口中对bean做一下修改的操作

调用到我们自定义的MyBeanPostProcessor实现类:

把这个beanDemo对象属性修改一下,修改完,再返回,将这个对象缓存到spring的一级缓存中。

http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%B8%85%E8%BF%9C%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E4%BE%9B%E5%8D%B5%E5%AD%90.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%B8%85%E8%BF%9C%E5%93%AA%E9%87%8C%E6%9C%89%E5%81%9A%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%B8%85%E8%BF%9C%E8%AF%95%E7%AE%A1%E4%BE%9B%E5%8D%B5%E5%A4%9A%E5%B0%91%E9%92%B1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%B8%85%E8%BF%9C%E4%BE%9B%E5%8D%B5%E4%B8%AD%E4%BB%8B%E5%85%AC%E5%8F%B8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%B8%85%E8%BF%9C%E4%BE%9B%E5%8D%B5%E6%A1%88%E4%BE%8B.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%B8%85%E8%BF%9C%E6%9C%89%E5%93%AA%E4%BA%9B%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E4%BE%9B%E5%8D%B5%E6%9C%BA%E6%9E%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%B8%85%E8%BF%9C%E5%93%AA%E5%AE%B6%E4%BE%9B%E5%8D%B5%E4%B8%8D%E6%8E%92%E9%98%9F%E7%9A%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E5%81%9A.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E4%BE%9B%E5%8D%B5%E8%87%AA%E6%80%80.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E6%AD%A3%E8%A7%84%E4%BE%9B%E5%8D%B5.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E4%BE%9B%E5%8D%B5%E8%B4%B9%E7%94%A8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E4%BE%9B%E5%8D%B5%E5%AD%90.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E5%93%AA%E9%87%8C%E6%9C%89%E5%81%9A%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E8%AF%95%E7%AE%A1%E4%BE%9B%E5%8D%B5%E5%A4%9A%E5%B0%91%E9%92%B1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E4%BE%9B%E5%8D%B5%E4%B8%AD%E4%BB%8B%E5%85%AC%E5%8F%B8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E4%BE%9B%E5%8D%B5%E6%A1%88%E4%BE%8B.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E6%9C%89%E5%93%AA%E4%BA%9B%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E4%BE%9B%E5%8D%B5%E6%9C%BA%E6%9E%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%8F%AD%E9%98%B3%E5%93%AA%E5%AE%B6%E4%BE%9B%E5%8D%B5%E4%B8%8D%E6%8E%92%E9%98%9F%E7%9A%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E5%81%9A.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E4%BE%9B%E5%8D%B5%E8%87%AA%E6%80%80.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E6%AD%A3%E8%A7%84%E4%BE%9B%E5%8D%B5.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E4%BE%9B%E5%8D%B5%E8%B4%B9%E7%94%A8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E4%BE%9B%E5%8D%B5%E5%AD%90.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E5%93%AA%E9%87%8C%E6%9C%89%E5%81%9A%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E8%AF%95%E7%AE%A1%E4%BE%9B%E5%8D%B5%E5%A4%9A%E5%B0%91%E9%92%B1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E4%BE%9B%E5%8D%B5%E4%B8%AD%E4%BB%8B%E5%85%AC%E5%8F%B8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E4%BE%9B%E5%8D%B5%E6%A1%88%E4%BE%8B.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E6%9C%89%E5%93%AA%E4%BA%9B%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E4%BE%9B%E5%8D%B5%E6%9C%BA%E6%9E%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E6%A2%85%E5%B7%9E%E5%93%AA%E5%AE%B6%E4%BE%9B%E5%8D%B5%E4%B8%8D%E6%8E%92%E9%98%9F%E7%9A%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E5%81%9A.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E4%BE%9B%E5%8D%B5%E8%87%AA%E6%80%80.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E6%AD%A3%E8%A7%84%E4%BE%9B%E5%8D%B5.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E4%BE%9B%E5%8D%B5%E8%B4%B9%E7%94%A8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E4%BE%9B%E5%8D%B5%E5%AD%90.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E5%93%AA%E9%87%8C%E6%9C%89%E5%81%9A%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E8%AF%95%E7%AE%A1%E4%BE%9B%E5%8D%B5%E5%A4%9A%E5%B0%91%E9%92%B1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E4%BE%9B%E5%8D%B5%E4%B8%AD%E4%BB%8B%E5%85%AC%E5%8F%B8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E4%BE%9B%E5%8D%B5%E6%A1%88%E4%BE%8B.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E6%9C%89%E5%93%AA%E4%BA%9B%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E4%BE%9B%E5%8D%B5%E6%9C%BA%E6%9E%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E8%82%87%E5%BA%86%E5%93%AA%E5%AE%B6%E4%BE%9B%E5%8D%B5%E4%B8%8D%E6%8E%92%E9%98%9F%E7%9A%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E5%81%9A.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E4%BE%9B%E5%8D%B5%E8%87%AA%E6%80%80.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E6%AD%A3%E8%A7%84%E4%BE%9B%E5%8D%B5.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E4%BE%9B%E5%8D%B5%E8%B4%B9%E7%94%A8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E4%BE%9B%E5%8D%B5%E5%AD%90.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E5%93%AA%E9%87%8C%E6%9C%89%E5%81%9A%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E8%AF%95%E7%AE%A1%E4%BE%9B%E5%8D%B5%E5%A4%9A%E5%B0%91%E9%92%B1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E4%BE%9B%E5%8D%B5%E4%B8%AD%E4%BB%8B%E5%85%AC%E5%8F%B8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E4%BE%9B%E5%8D%B5%E6%A1%88%E4%BE%8B.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E6%9C%89%E5%93%AA%E4%BA%9B%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E4%BE%9B%E5%8D%B5%E6%9C%BA%E6%9E%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E7%8E%89%E6%9E%97%E5%93%AA%E5%AE%B6%E4%BE%9B%E5%8D%B5%E4%B8%8D%E6%8E%92%E9%98%9F%E7%9A%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E5%81%9A.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E4%BE%9B%E5%8D%B5%E8%87%AA%E6%80%80.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E6%AD%A3%E8%A7%84%E4%BE%9B%E5%8D%B5.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E4%BE%9B%E5%8D%B5%E8%B4%B9%E7%94%A8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E5%93%AA%E9%87%8C%E5%8F%AF%E4%BB%A5%E4%BE%9B%E5%8D%B5%E5%AD%90.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E5%93%AA%E9%87%8C%E6%9C%89%E5%81%9A%E4%BE%9B%E5%8D%B5%E8%AF%95%E7%AE%A1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E8%AF%95%E7%AE%A1%E4%BE%9B%E5%8D%B5%E5%A4%9A%E5%B0%91%E9%92%B1.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E4%BE%9B%E5%8D%B5%E4%B8%AD%E4%BB%8B%E5%85%AC%E5%8F%B8.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E4%BE%9B%E5%8D%B5%E6%A1%88%E4%BE%8B.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E6%9C%89%E5%93%AA%E4%BA%9B%E6%AF%94%E8%BE%83%E5%A4%A7%E7%9A%84%E4%BE%9B%E5%8D%B5%E6%9C%BA%E6%9E%84.html
http://news.leju.com/tag/%E3%80%96%E5%BE%AE1%E2%92%8A26%E2%92%8F1%E2%92%8A29%E2%92%909%E3%80%97%E5%8C%97%E6%B5%B7%E5%93%AA%E5%AE%B6%E4%BE%9B%E5%8D%B5%E4%B8%8D%E6%8E%92%E9%98%9F%E7%9A%84.html

https://mvp.leju.com/article/6678961028585839046.html
https://mvp.leju.com/article/6678960999385094597.html
https://mvp.leju.com/article/6678960971979512258.html
https://mvp.leju.com/article/6678960946134211075.html
https://mvp.leju.com/article/6678960915956193873.html
https://www.bilibili.com/read/cv6452727
https://mvp.leju.com/article/6678494352652196850.html
https://mvp.leju.com/article/6678494332561480305.html
https://mvp.leju.com/article/6678494321375271536.html
https://mvp.leju.com/article/6678494310549773293.html
https://mvp.leju.com/article/6678493262795856428.html
https://mvp.leju.com/article/6678205331350838245.html
https://mvp.leju.com/article/6678205305270655986.html
https://mvp.leju.com/article/6678205263474416036.html
https://mvp.leju.com/article/6678205240422521802.html
https://mvp.leju.com/article/6678204430665997197.html
https://mvp.leju.com/article/6677858635899034093.html
https://mvp.leju.com/article/6677858598750084008.html
https://mvp.leju.com/article/6677858566986619626.html
https://mvp.leju.com/article/6677858484677598114.html
https://mvp.leju.com/article/6677858534535289764.html
https://www.bilibili.com/read/cv6420999
https://www.bilibili.com/read/cv6421013
https://www.bilibili.com/read/cv6421044
https://www.bilibili.com/read/cv6421255
https://mvp.leju.com/article/6677098333934803798.html
https://mvp.leju.com/article/6677098307791707085.html
https://mvp.leju.com/article/6677098271485811035.html
https://mvp.leju.com/article/6677098222366317515.html
https://mvp.leju.com/article/6677096728279734823.html
https://mvp.leju.com/article/6676679887673711476.html
https://mvp.leju.com/article/6676679880363039603.html
https://mvp.leju.com/article/6676679700238654315.html
https://mvp.leju.com/article/6676679652805270117.html
https://mvp.leju.com/article/6676679618533612128.html
https://www.bilibili.com/medialist/detail/ml984341513
https://www.bilibili.com/medialist/play/ml984432813
https://www.bilibili.com/medialist/detail/ml984432813
https://www.bilibili.com/medialist/detail/ml984437613
https://www.bilibili.com/medialist/detail/ml984437413
https://www.bilibili.com/medialist/detail/ml984437313
https://www.bilibili.com/medialist/detail/ml984436913
https://www.bilibili.com/medialist/detail/ml984436713
https://www.bilibili.com/medialist/detail/ml984436013
https://www.bilibili.com/medialist/detail/ml984435213
https://www.bilibili.com/medialist/detail/ml984434913
https://www.bilibili.com/medialist/detail/ml984434613
https://www.bilibili.com/medialist/detail/ml984360013
https://www.bilibili.com/medialist/detail/ml984359813
https://www.bilibili.com/medialist/detail/ml984359013
https://www.bilibili.com/medialist/detail/ml984359413
https://www.bilibili.com/medialist/detail/ml984358913
https://www.bilibili.com/medialist/detail/ml984358213
https://www.bilibili.com/medialist/detail/ml984357713
https://www.bilibili.com/medialist/detail/ml984357513
https://www.bilibili.com/medialist/detail/ml984357413
https://www.bilibili.com/medialist/detail/ml984265613
https://www.bilibili.com/medialist/detail/ml984356813
https://www.bilibili.com/medialist/detail/ml984265513
https://www.bilibili.com/medialist/detail/ml984265313
https://www.bilibili.com/medialist/detail/ml984265213
https://www.bilibili.com/medialist/detail/ml984264913
https://www.bilibili.com/medialist/detail/ml984264813
https://www.bilibili.com/medialist/detail/ml984264613
https://www.bilibili.com/medialist/detail/ml984264513
https://www.bilibili.com/medialist/detail/ml984264213
https://www.bilibili.com/medialist/detail/ml984264113
https://www.bilibili.com/medialist/detail/ml984263913
https://www.bilibili.com/medialist/detail/ml984263513
https://www.bilibili.com/medialist/detail/ml984263113
https://www.bilibili.com/medialist/detail/ml984262713
https://www.bilibili.com/medialist/detail/ml984262413
https://www.bilibili.com/medialist/detail/ml984262613
https://www.bilibili.com/medialist/detail/ml984261913
https://www.bilibili.com/medialist/detail/ml984184213
https://www.bilibili.com/medialist/detail/ml984184013
https://www.bilibili.com/medialist/detail/ml984183813
https://www.bilibili.com/medialist/detail/ml984183513
https://www.bilibili.com/medialist/detail/ml984183313
https://www.bilibili.com/medialist/detail/ml984182913
https://www.bilibili.com/medialist/detail/ml984182713
https://www.bilibili.com/medialist/detail/ml984182513
https://www.bilibili.com/medialist/detail/ml984182613
https://www.bilibili.com/medialist/detail/ml984181413
https://www.bilibili.com/medialist/detail/ml984180913

总结:

BeanPostProcessor接口主要是对bean对象做一些自定义的操作,修改bean对象的信息,aop代理也是通过这种方式实现的,

在refresh的registryBeanPostProcessor方法中实例化BeanPostProcessor对象,并且注册到beanFactory容器的beanPostProcessors的缓存中,

然后在后续的操作中拦截使用。

你可能感兴趣的:(spring源码分析——BeanPostProcessor接口)