ConfigurationClassParser avoids double registration of nested classes which extend their containing class
Issue: SPR-12195
This commit is contained in:
parent
f394c8aa2a
commit
824c90d2bf
|
@ -311,7 +311,8 @@ class ConfigurationClassParser {
|
|||
*/
|
||||
private void processMemberClasses(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
|
||||
for (SourceClass memberClass : sourceClass.getMemberClasses()) {
|
||||
if (ConfigurationClassUtils.isConfigurationCandidate(memberClass.getMetadata())) {
|
||||
if (ConfigurationClassUtils.isConfigurationCandidate(memberClass.getMetadata()) &&
|
||||
!memberClass.getMetadata().getClassName().equals(configClass.getMetadata().getClassName())) {
|
||||
processConfigurationClass(memberClass.asConfigClass(configClass));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
|||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.annotation.ComponentScan.Filter;
|
||||
import org.springframework.context.annotation.ComponentScanParserTests.KustomAnnotationAutowiredBean;
|
||||
import org.springframework.context.annotation.componentscan.simple.ClassWithNestedComponents;
|
||||
import org.springframework.context.annotation.componentscan.simple.SimpleComponent;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.tests.context.SimpleMapScope;
|
||||
|
@ -115,6 +116,8 @@ public class ComponentScanAnnotationIntegrationTests {
|
|||
ctx.refresh();
|
||||
ctx.getBean(ComposedAnnotationConfig.class);
|
||||
ctx.getBean(SimpleComponent.class);
|
||||
ctx.getBean(ClassWithNestedComponents.NestedComponent.class);
|
||||
ctx.getBean(ClassWithNestedComponents.OtherNestedComponent.class);
|
||||
assertThat("config class bean not found",
|
||||
ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig"), is(true));
|
||||
assertThat("@ComponentScan annotated @Configuration class registered directly against " +
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.annotation.componentscan.simple;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
public class ClassWithNestedComponents {
|
||||
|
||||
@Component
|
||||
public static class NestedComponent extends ClassWithNestedComponents {
|
||||
}
|
||||
|
||||
@Component
|
||||
public static class OtherNestedComponent extends ClassWithNestedComponents {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue