Results 1 to 3 of 3

Thread: A problem with excluding beans with multiple component-scan declaration

Hybrid View

  1. #1
    Join Date
    Sep 2007
    Posts
    11

    Question A problem with excluding beans with multiple component-scan declaration

    Hi,

    I noticed some strange behavior of context:component-scan. I thought that packages from multiple component-scan declarations are combined together with corresponding exclude/include-filter values. Unfortunately it seems that exclude-filter is taken into consideration only when a package is not included in any other component-scan.

    In the following example a bean in foo.bar.sub package will not be excluded:

    Code:
        <context:component-scan base-package="foo"/>
    
        <context:component-scan base-package="foo.bar">
            <context:exclude-filter type="regex" expression="foo.bar.sub.*"/>
        </context:component-scan>
    Is it an expected behavior?
    It can tend to hard to find problems when some included XML configuration accidentally does scanning at higher package level. Tested with Spring 3.0.6.

    Regards
    Marcin

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Those are 2 single component-scan which aren't combined. The first (foo) scans everything and the next scans foo.bar with some exclusions, basically leading to (potentially) duplicate bean instances.

    Simply combine them into one. You can simply put a comma separated list into base-package...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2007
    Posts
    11

    Default

    Thanks for your reply.

    The problem is that sometimes you can't easly combine multiple component-scan tags. For example the application scan the whole for.bar package, but in some test you would like to provide a different instance of one selected bean. The ability to import production context, exclude that bean and add the testing one would be convenient.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •