Announcement Announcement Module
No announcement yet.
component-scan include filter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • component-scan include filter

    When a regex include filter is used to customize scanning, Spring container loads every class that matches the regular expression even though they are not annotated with @Component, @Repository, @Service, @Controller.

    For example : Following is trying to load every single class that matches the regular expression

    <context:component-scan base-package="a.b.c">
    <context:include-filter type="regex" expression="a.b.c.*.web.*.*"/>

    I have looked at the source code, and my understanding is that it matches atleast one include filter, and Stereotype annotation presence is also done by include filters.
    This is causing the app Context to bloat up.

    The documentation says that by including custom filters we will be extending the default behavior, which is kind of confusing. Please clarify the documentation and let us know if there is a better way to do this.

    "5.10.3 Using filters to customize scanning
    By default, classes annotated with @Component, @Repository, @Service, @Controller, or a custom annotation that itself is annotated with @Component are the only detected candidate components. However, you can modify and extend this behavior simply by applying custom filters. Add them as include-filter or exclude-filter sub-elements of the component-scan element. Each filter element requires the type and expression attributes. The following table describes the filtering options"