You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow recursive use of @ComponentScan [SPR-8307] #12956
Currently (in Spring 3.1 M1), @ComponentScan annotations are not processed recursively. For example:
package one;
@Configuration
@ComponentScan("two")
public class ConfigOne { }
package two;
@Configuration
@ComponentScan("three")
public class ConfigTwo { }
package three;
@Component
public class MyComponent { }
Under Spring 3.1 M1, the following behavior will occur:
package bootstrap;
public class Bootstrap {
public static void main(String... args) {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigOne.class);
ctx.refresh();
ctx.getBean(ConfigOne.class); // success
ctx.getBean(ConfigTwo.class); // success - 1st level @ComponentScan processed
ctx.getBean(MyComponent.class); // fails - 2nd level @ComponentScan not processed
}
}
Once the recursion logic is complete, it will also be important to detect and prevent cycles in scanned packages, e.g. @ComponentScan("one")=>@ComponentScan("two")=>@ComponentScan("one"). This is not unlike the cycle detection we already do with the @Import annotation.
Author: Chris Beams <[email protected]>
Date: Sun May 8 16:49:42 2011 +0800
Allow recursive use of @ComponentScan
Prior to this change, @ComponentScan annotations were only processed at
the first level of depth. Now, the set of bean definitions resulting
from each declaration of @ComponentScan is checked for configuration
classes that declare @ComponentScan, and recursion is performed as
necessary.
Cycles between @ComponentScan declarations are detected as well. See
CircularComponentScanException.
Issue: SPR-8307
Activity
spring-projects-issues commentedon May 8, 2011
Chris Beams commented