Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions