**Affects: 2.x - latest
Lets say you have RestControllerA
with RepositoryA
and RestControllerB
with RepositoryB
.
Now you want to test the web layer with the @WebMvcTest(RestControllerA::class)
annotation.
Then spring complains with this exception:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type RepositoryB.
So it seems like that there is a bug where spring wants to load RestControllerB with RepositoryB, even when its not necessary because i specified the class that i want to test.
Comment From: snicoll
@WebMvcTest
is part of Spring Boot so I've moved your report to the appropriate issue tracker.
Please share a small sample that reproduces the issue you've described as @WebMvcTest
on a given controller shouldn't force the lookup of RepositoryB
.
Comment From: Philosobyte
Are you using @ComponentScan
anywhere? I noticed in #21216 that adding @ComponentScan
will override the TypeExcludeFilter
being used for @WebMvcTest
.
Comment From: snicoll
@Philosobyte thank you for trying to help but rather than guessing what the problem might be, we'll look at the sample.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: Ditscheridou
Sorry im currently very busy with other task, so i cant provide a mwe in the requested time. @Philosobyte im indeed using ComponentScan in my application. I wall look in to it when i got the time
Comment From: snicoll
If you are using @ComponentScan
, then this is probably working as advertized, check this section of the documentation for more details.
I am going to close this now and we can reconsider if you still have a problem and a sample that we can review.