I have a component that I want to exclude from a @ComponentScan in a particular @Configuration:
@Component(\"foo\") class Foo {
...
Using explicit types in scan filters is ugly for me. I believe more elegant approach is to create own marker annotation:
@Retention(RetentionPolicy.RUNTIME)
public @interface IgnoreDuringScan {
}
Mark component that should be excluded with it:
@Component("foo")
@IgnoreDuringScan
class Foo {
...
}
And exclude this annotation from your component scan:
@ComponentScan(excludeFilters = @Filter(IgnoreDuringScan.class))
public class MySpringConfiguration {}