Skip to content

Commit 0948edb

Browse files
committed
Nested configuration class introspection check on concrete class
Issue: SPR-16839
1 parent c8869d9 commit 0948edb

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected void processConfigurationClass(ConfigurationClass configClass) throws
262262
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass)
263263
throws IOException {
264264

265-
if (sourceClass.getMetadata().isAnnotated(Component.class.getName())) {
265+
if (configClass.getMetadata().isAnnotated(Component.class.getName())) {
266266
// Recursively process any member (nested) classes first
267267
processMemberClasses(configClass, sourceClass);
268268
}

spring-context/src/test/java/org/springframework/context/annotation/NestedConfigurationClassTests.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -201,6 +201,27 @@ public void twoLevelsWithNoBeanMethods() {
201201
assertNotEquals(l2i1.toString(), l2i2.toString());
202202
}
203203

204+
@Test
205+
public void twoLevelsOnNonAnnotatedBaseClass() {
206+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
207+
ctx.register(L0ConfigConcrete.class);
208+
ctx.refresh();
209+
210+
assertFalse(ctx.getBeanFactory().containsSingleton("l0ConfigConcrete"));
211+
Object l0i1 = ctx.getBean(L0ConfigConcrete.class);
212+
Object l0i2 = ctx.getBean(L0ConfigConcrete.class);
213+
assertTrue(l0i1 == l0i2);
214+
215+
Object l1i1 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.class);
216+
Object l1i2 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.class);
217+
assertTrue(l1i1 != l1i2);
218+
219+
Object l2i1 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.L2ConfigEmpty.class);
220+
Object l2i2 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.L2ConfigEmpty.class);
221+
assertTrue(l2i1 == l2i2);
222+
assertNotEquals(l2i1.toString(), l2i2.toString());
223+
}
224+
204225

205226
@Configuration
206227
@Lazy
@@ -365,4 +386,24 @@ protected static class L2ConfigEmpty {
365386
}
366387
}
367388

389+
390+
static class L0ConfigBase {
391+
392+
@Component
393+
@Scope("prototype")
394+
static class L1ConfigEmpty {
395+
396+
@Component
397+
@Scope(value = "prototype", proxyMode = ScopedProxyMode.TARGET_CLASS)
398+
protected static class L2ConfigEmpty {
399+
}
400+
}
401+
}
402+
403+
404+
@Component
405+
@Lazy
406+
static class L0ConfigConcrete extends L0ConfigBase {
407+
}
408+
368409
}

0 commit comments

Comments
 (0)