There is in fact a cleaner way to configure such integration tests.
The answer lies in proper separation of concerns, not only at the class level but also at the package level.
It is always recommended that both implementation and configuration classes reside in package hierarchies that allow for proper separation of concerns. Specifically for a web application, it is highly advisable to ensure that web components and web configuration reside in a dedicated 'web' package. For example, you could consider a package hierarchy similar to the following:
com.example.domain
com.example.service
com.example.repository
com.example.web
With such a hierarchy you can simplify your component scanning configuration by including only those base packages that are pertinent to the current application or test scenario. By doing this there is typically no need to use exclusion filters for things you don't want. Instead, just specify packages you do want.
By the way, specifying "com.bignibou"
as your base package is actually a worst practice since it is all-encompassing.
So give it a shot with explicit package inclusions (instead of excluding @Controller
, @ControllerAdvice
, etc.) and see if that doesn't make your life easier. ;)
Regards,
Sam