X Tutup
Skip to content

Commit f18fa08

Browse files
committed
ConfigurationClassPostProcessor supports use of same processor instance with several factories (SPR-8527)
1 parent aa4ecdb commit f18fa08

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

org.springframework.context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.context.annotation;
1818

1919
import java.io.IOException;
20+
import java.util.HashSet;
2021
import java.util.LinkedHashMap;
2122
import java.util.LinkedHashSet;
2223
import java.util.Map;
@@ -80,9 +81,9 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
8081

8182
private boolean setMetadataReaderFactoryCalled = false;
8283

83-
private boolean postProcessBeanDefinitionRegistryCalled = false;
84+
private final Set<Integer> registriesPostProcessed = new HashSet<Integer>();
8485

85-
private boolean postProcessBeanFactoryCalled = false;
86+
private final Set<Integer> factoriesPostProcessed = new HashSet<Integer>();
8687

8788

8889
/**
@@ -130,15 +131,16 @@ public int getOrder() {
130131
* Derive further bean definitions from the configuration classes in the registry.
131132
*/
132133
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
133-
if (this.postProcessBeanDefinitionRegistryCalled) {
134+
int registryId = System.identityHashCode(registry);
135+
if (this.registriesPostProcessed.contains(registryId)) {
134136
throw new IllegalStateException(
135-
"postProcessBeanDefinitionRegistry already called for this post-processor");
137+
"postProcessBeanDefinitionRegistry already called for this post-processor against " + registry);
136138
}
137-
if (this.postProcessBeanFactoryCalled) {
139+
if (this.factoriesPostProcessed.contains(registryId)) {
138140
throw new IllegalStateException(
139-
"postProcessBeanFactory already called for this post-processor");
141+
"postProcessBeanFactory already called for this post-processor against " + registry);
140142
}
141-
this.postProcessBeanDefinitionRegistryCalled = true;
143+
this.registriesPostProcessed.add(registryId);
142144
processConfigBeanDefinitions(registry);
143145
}
144146

@@ -147,12 +149,13 @@ public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) {
147149
* by replacing them with CGLIB-enhanced subclasses.
148150
*/
149151
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
150-
if (this.postProcessBeanFactoryCalled) {
152+
int factoryId = System.identityHashCode(beanFactory);
153+
if (this.factoriesPostProcessed.contains(factoryId)) {
151154
throw new IllegalStateException(
152-
"postProcessBeanFactory already called for this post-processor");
155+
"postProcessBeanFactory already called for this post-processor against " + beanFactory);
153156
}
154-
this.postProcessBeanFactoryCalled = true;
155-
if (!this.postProcessBeanDefinitionRegistryCalled) {
157+
this.factoriesPostProcessed.add((factoryId));
158+
if (!this.registriesPostProcessed.contains((factoryId))) {
156159
// BeanDefinitionRegistryPostProcessor hook apparently not supported...
157160
// Simply call processConfigBeanDefinitions lazily at this point then.
158161
processConfigBeanDefinitions((BeanDefinitionRegistry) beanFactory);

0 commit comments

Comments
 (0)
X Tutup