Results 1 to 4 of 4

Thread: context:component-scan - exclude-filter for a @component class isnt working

  1. #1
    Join Date
    Sep 2012
    Posts
    2

    Default context:component-scan - exclude-filter for a @component class isnt working

    i would like to exclude a special class from JUnit testing.

    my project has a class xEventHandler annotated with @Component...and i dont want spring to use this class while junit testing.

    my ApplicationTestContext.xml looks like this:
    Code:
    <context:component-scan base-package="com.company">
          ...
          <context:exclude-filter expression="com\.company\.xyz\.xEventHandler\.java" type="regex"/>
          ...
    </context:component-scan>
    however...the class gets entered because of the @Component annotation...how can i fix is?
    Last edited by ds-fh; Sep 20th, 2012 at 02:36 AM. Reason: added code tags

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

    Default

    Please use [ code][/code ] tags when posting code, that way it remains readable.

    If the component gets picked up either your expression is wrong or you have another component-scan which picks up the component.

    Edit: Your filter is wrong... It should be the classname not the filename remove .java from your filter (as a start). Also why not use assignable instead of regex if it is a single class to exclude?
    Last edited by Marten Deinum; Sep 19th, 2012 at 08:40 AM.
    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 2012
    Posts
    2

    Default

    Quote Originally Posted by Marten Deinum View Post
    Edit: Your filter is wrong... It should be the classname not the filename remove .java from your filter
    that was the misstake...thanks. shouldn´t be .java.


    tried type="assignable" first, but ...

    Code:
    java.lang.IllegalStateException: Failed to load ApplicationContext
    	at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    .
    .
    ....
    Last edited by ds-fh; Sep 20th, 2012 at 09:53 AM.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Without the full stacktrace it is quite hard to pinpoint the problem with 'assignable'...
    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

Posting Permissions

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