To make it annotation-based, you'd annotate each class you wanted excluded for integration tests with something like @com.example.annotation.ExcludedFromITests. Then the component-scan would look like:
That's clearer because now you've documented in the source code itself that the class is not intended to be included in an application context for integration tests.
I am using @ComponentScan as follows for the same use case. This is the same as BenSchro10's XML answer but this uses annotations. Both use a filter with type=AspectJ
This overrides the default resourcePattern which is "**/*.class".
This would seem like the most type-safe way to ONLY include your base package since that resourcePattern would always be the same and relative to your base package.
It seems you've done this through XML, but if you were working in new Spring best practice, your config would be in Java, and you could exclude them as so:
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "net.example.tool",
excludeFilters = {@ComponentScan.Filter(
type = FilterType.ASSIGNABLE_TYPE,
value = {JPAConfiguration.class, SecurityConfig.class})
})
You can also use @SpringBootApplication, which according to Spring documentation does the same functionality as the following three annotations:
@Configuration, @EnableAutoConfiguration@ComponentScan
in one annotation.
@SpringBootApplication(exclude= {Foo.class})
public class MySpringConfiguration {}
Just an addition to existing answers.
If you want to exclude classes from sub-packages but not from the base package then you can change "com.example.ignore.* to "com.example.ignore.*..*" as follows