Issue
I am trying to create a @WebFluxTest in spring to test my controllers.
@WebFluxTest(value = {MyController.class})
public class MyControllerTest {
@MockBean
private MyService service;
@Autowired
private WebTestClient webTestClient;
@Test
void testSomething() {
...
}
However, when I execute the test, I get a lot of: org.springframework.beans.factory.NoSuchBeanDefinitionException for dependencies of @Component s. Meaning that, Spring is trying to find dependencies of @Component when it should ignore those. I understand that if I use @WebFluxTest, spring should not scan the classpath for any @Component.
My Application class is only annotated with @SpringBootApplication.
What could I be missing here?
SOLUTION UPDATE:
So, I know what was happening. Actually, the class that I had annotated with @Component was an implementation of a WebFilter, and if I check the filter configured for a WebFluxTest (WebFluxTypeExcludeFilter) it adds WebFilter to the include part. That is why Spring was picking it up.
Solution
So, I know what was happening. Actually, the class that I had annotated with @Component was an implementation of a WebFilter, and if I check the filter configured for a WebFluxTest (WebFluxTypeExcludeFilter) it adds WebFilter to the include part. That is why Spring was picking it up.
Answered By - user3013172
Answer Checked By - Clifford M. (JavaFixing Volunteer)