17
17
package org .apache .dubbo .config .spring .beans .factory .annotation ;
18
18
19
19
import org .apache .dubbo .common .utils .Assert ;
20
+ import org .apache .dubbo .common .utils .StringUtils ;
20
21
import org .apache .dubbo .config .AbstractConfig ;
21
22
import org .apache .dubbo .config .spring .context .annotation .DubboConfigBindingRegistrar ;
22
23
import org .apache .dubbo .config .spring .context .annotation .EnableDubboConfigBinding ;
29
30
import org .springframework .beans .BeansException ;
30
31
import org .springframework .beans .factory .InitializingBean ;
31
32
import org .springframework .beans .factory .config .BeanPostProcessor ;
33
+ import org .springframework .beans .factory .config .ConfigurableListableBeanFactory ;
34
+ import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
35
+ import org .springframework .beans .factory .support .BeanDefinitionRegistryPostProcessor ;
36
+ import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
32
37
import org .springframework .context .ApplicationContext ;
33
38
import org .springframework .context .ApplicationContextAware ;
34
39
import org .springframework .core .annotation .AnnotationAwareOrderComparator ;
49
54
* @since 2.5.8
50
55
*/
51
56
52
- public class DubboConfigBindingBeanPostProcessor implements BeanPostProcessor , ApplicationContextAware , InitializingBean {
57
+ public class DubboConfigBindingBeanPostProcessor implements BeanPostProcessor , ApplicationContextAware , InitializingBean
58
+ , BeanDefinitionRegistryPostProcessor {
53
59
54
60
private final Log log = LogFactory .getLog (getClass ());
55
61
@@ -67,6 +73,8 @@ public class DubboConfigBindingBeanPostProcessor implements BeanPostProcessor, A
67
73
68
74
private ApplicationContext applicationContext ;
69
75
76
+ private BeanDefinitionRegistry beanDefinitionRegistry ;
77
+
70
78
private boolean ignoreUnknownFields = true ;
71
79
72
80
private boolean ignoreInvalidFields = true ;
@@ -145,6 +153,15 @@ public void setDubboConfigBinder(DubboConfigBinder dubboConfigBinder) {
145
153
146
154
@ Override
147
155
public Object postProcessAfterInitialization (Object bean , String beanName ) throws BeansException {
156
+ if (bean instanceof AbstractConfig ) {
157
+ String id = ((AbstractConfig ) bean ).getId ();
158
+ if (beanDefinitionRegistry != null && beanDefinitionRegistry instanceof DefaultListableBeanFactory ) {
159
+ DefaultListableBeanFactory factory = (DefaultListableBeanFactory ) beanDefinitionRegistry ;
160
+ if (!StringUtils .isBlank (id ) && !factory .hasAlias (beanName , id )) {
161
+ beanDefinitionRegistry .registerAlias (beanName , id );
162
+ }
163
+ }
164
+ }
148
165
return bean ;
149
166
}
150
167
@@ -203,4 +220,15 @@ protected DubboConfigBinder createDubboConfigBinder(Environment environment) {
203
220
return defaultDubboConfigBinder ;
204
221
}
205
222
223
+ @ Override
224
+ public void postProcessBeanDefinitionRegistry (BeanDefinitionRegistry registry ) throws BeansException {
225
+ if (this .beanDefinitionRegistry == null ) {
226
+ this .beanDefinitionRegistry = registry ;
227
+ }
228
+ }
229
+
230
+ @ Override
231
+ public void postProcessBeanFactory (ConfigurableListableBeanFactory beanFactory ) throws BeansException {
232
+ //do nothing here
233
+ }
206
234
}
0 commit comments