title: exclude @Component from @ComponentScan
body: <p>I have a component that I want to exclude from a <code>@ComponentScan</code> in a particular <code>@Configuration</code>:</p>
  <pre><code>@Component(&quot;foo&quot;) class Foo {
  ...
  }
  </code></pre>
  <p>Otherwise, it seems to clash with some other class in my project. I don't fully understand the collision, but if I comment out the <code>@Component</code> annotation, things work like I want them to. But other projects that rely on this library expect this class to be managed by Spring, so I want to skip it only in my project.</p>
  <p>I tried using <code>@ComponentScan.Filter</code>:</p>
  <pre><code>@Configuration 
  @EnableSpringConfigured
  @ComponentScan(basePackages = {&quot;com.example&quot;}, excludeFilters={
    @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE, value=Foo.class)})
  public class MySpringConfiguration {}
  </code></pre>
  <p>but it doesn't appear to work. If I try using <code>FilterType.ASSIGNABLE_TYPE</code>, I get a strange error about being unable to load some seemingly random class:</p>
  <blockquote>
  <p>Caused by: java.io.FileNotFoundException: class path resource [junit/framework/TestCase.class] cannot be opened because it does not exist</p>
  </blockquote>
  <p>I also tried using <code>type=FilterType.CUSTOM</code> as following:</p>
  <pre><code>class ExcludeFooFilter implements TypeFilter {
      @Override
      public boolean match(MetadataReader metadataReader,
              MetadataReaderFactory metadataReaderFactory) throws IOException {
          return metadataReader.getClass() == Foo.class;
      }
  }
  
  @Configuration @EnableSpringConfigured
  @ComponentScan(basePackages = {&quot;com.example&quot;}, excludeFilters={
    @ComponentScan.Filter(type=FilterType.CUSTOM, value=ExcludeFooFilter.class)})
  public class MySpringConfiguration {}
  </code></pre>
  <p>But that doesn't seem to exclude the component from the scan like I want.</p>
  <p>How do I exclude it?</p>