Skip to content

Allow recursive use of @ComponentScan [SPR-8307] #12956

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Issue Links:

Referenced from: commits 6991cd9, d0c31ad

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions