Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ComponentScan's includeFilters javadoc is misleading [SPR-13844] #18417

Closed
spring-projects-issues opened this issue Jan 6, 2016 · 1 comment
Assignees
Labels
type: documentation A documentation task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 6, 2016

Louis-Rémi opened SPR-13844 and commented

Issue

Reading this javadoc gives the impression that these filters are applied after the basePackages to further narrow down the candidate components.

/**
 * Specifies which types are eligible for component scanning.
 * <p>Further narrows the set of candidate components from everything in
 * {@link #basePackages} to everything in the base packages that matches
 * the given filter or filters.
 * @see #resourcePattern
 */
Filter[] includeFilters() default {};

But in fact, along with usual annotated types since useDefaultFilters==true, all types under the includeFilters are candidate components (scanned and instanciated). Even those not annotated or meta-annotated with @Component.

It should be made clearer to avoid such misunderstanding.

Additional information

I would've expected this behavior under an attribute named forceFilters

includeFilters behavior could be described as: "Forces all types under basePackages and these filters to be candidate components."

Example to illustrate the situation in regards to the documentation.

@ComponentScan(basePackages = { "com.aom" },
        includeFilters = @Filter(type = FilterType.ASPECTJ, pattern = "com.aom..middlepackage..*"))

All types under com.aom..middlepackage..* will be scanned and instanciated as beans, Even if not annotated* or meta-annotated with @Component


Affects: 4.2.4

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jan 20, 2016

Juergen Hoeller commented

Indeed, each include filter will be applied independently, not chained after the default filters. So any type under the specified base packages which matches a given filter will be included, even if it does not match the default filters (i.e. is not annotated with @Component). I've added explicit notes on that to the documentation.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

2 participants