Comment From: snicoll
@wilkinsona those are usually defined within a @Configuration class so I am wondering how we would detect that.
Comment From: wilkinsona
And now that you've asked, I'm wondering too. Without support in the Framework for filtering the beans produced by a configuration class that's similar to the filtering offered for component scanning, I can't think how we can do it.
Comment From: snicoll
It's worse than that even. The router is linked to one or more handlers. I think a good match in that world would be to split routers per area and the slice is the router.
But even if you have that you need to add the handler beans. And those are regular components with methods in them. So we would have to scan the injection point upfront to add them. Sounds quite complicated.
Comment From: snicoll
@wilkinsona removing from the 2.0 bucket as I don't see a way to implement this at the moment. Worth considering in par with the "programmatic/explicit configuration"
Comment From: kizux
Hello there ! Any news about this point ? I am not using controller but new functional endpoints. Will be really awesome to use WebFluxTest. Thank you !
Comment From: wilkinsona
No news at this time (this issue would have been updated if there was). As things stand, we don't think it's possible to do what we'd like, certainly not without some changes in Spring Framework and maybe not at all.
Comment From: kizux
If it can help people who are using functional endpoints as I do. I so finally test them by this way :
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {RouteConfiguration.class, UserHandler.class})
@WebFluxTest
public class UserHandlerTest
{
@Autowired
private ApplicationContext context;
@MockBean(name="userService")
private UserService userService;
private WebTestClient testClient;
@Before
public void setUp()
{
testClient = WebTestClient.bindToApplicationContext(context).build();
}
...
The WebFluxTest annotation keep avoid to load other things than RestController and I customize the ContextConfiguration to load my functional endpoints.
Comment From: mythicallage
Hello there!
I tried the below and It works for me.
@WebFluxTest(controllers = {RouteConfiguration.class, UserHandler.class})
public class UserHandlerTest {
@Autowired
private WebTestClient testClient;
@MockBean(name="userService")
private UserService userService;
...
}
Comment From: NadChel
Hello there!
I tried the below and It works for me.
```java @WebFluxTest(controllers = {RouteConfiguration.class, UserHandler.class}) public class UserHandlerTest { @Autowired private WebTestClient testClient;
@MockBean(name="userService") private UserService userService; ... } ```
I confirm. My Boot is at 3.2.3