Closed
Description
Chris Beams opened SPR-8307 and commented
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.
Affects: 3.1 M1
Attachments:
- mylyn-context.zip (131.35 kB)
Issue Links:
- Add @ComponentScan annotation [SPR-7194] #11848 Add
@ComponentScan
annotation - Allow @Configuration classes to self-@ComponentScan [SPR-8808] #13450 Allow
@Configuration
classes to self-@ComponentScan
- @Configuration classes are not enhanced with @ComponentScan [SPR-8069] #12724
@Configuration
classes are not enhanced with@ComponentScan
("supersedes")