Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RouterFunction bean id to the RouterFunctions.Visitor [SPR-17579] #22111

spring-projects-issues opened this issue Dec 7, 2018 · 1 comment
in: web status: declined type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Dec 7, 2018

Alex Boyko opened SPR-17579 and commented

STS team attempts to find a spot in the source code that declares RM using functional style using the JSON data from the Actuator.

For example for the source code

public RouterFunction<ServerResponse> route(VetsHandler vetsHandler) \{

	return RouterFunctions
		.route(RequestPredicates.GET("/vets").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), vetsHandler::vets)
		.andRoute(RequestPredicates.GET("/vets.html"), vetsHandler::vetsHtml);


We'd like to find for /vets and /vets.html routes the method:

public RouterFunction<ServerResponse> route(...)

There are two pieces of data to help find the method: predicate and handler.

The handler data should be the most helpful in matching the method. However, based on the handler data we cannot match the route() method unfortunately. The lambda with magic numbers is useless in this case.

It'd be great if each router function could hold the id of the RouterFunction bean for example or expose the RouterFunction bean id in the RouterFunctions.Visitor such that instead of

void route(RequestPredicate predicate, HandlerFunction<?> handlerFunction)

we'd have:

void route(RequestPredicate predicate, HandlerFunction<?> handlerFunction, String beanId)

Down the stream Boot Actuator could pick that bean id and pass it down to JMX bean data for the functional RM. Thus we on the STS side could find the method defining bean with the id and then associate that place in the source code to a place where functional RM is defined.

Otherwise, currently actuator has an aggregate RouterFuctions object that has all RMs and extracts predicates and handlers for each RM from the aggregate RouterFuctions object with a help of RouterFunctions.Visitor

Here is the related Boot Actuator issue: spring-projects/spring-boot#15230

Affects: 5.1.3

Reference URL: spring-projects/spring-boot#15230

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 11, 2018

Arjen Poutsma commented

The vast majority of RouterFunction in a given WebFlux.fn app are not Spring Beans. In your example, the only RouterFunction bean is the one created in route. This router bean is composed of two other routes (to vets and vetsHtml), but these are not registered as Spring beans. Having just one or perhaps two RouterFunction beans is quite typical. Additionally, there is a way to run WebFlux.fn outside of an application context (see the reference docs), in which case none of the router functions are Spring beans.

Given that most router functions are not Spring beans, we are not going to change the visitor API to take a bean identifier, as it would be null for most routes. However, it is quite easy to get the bean id yourself in your visitor, if you still want to. All you need in your RouterFunctions.Visitor implementation is a reference to the app context, find all RouterFunction beans in said context, and do a simple object equality comparison (==) against them in the route method to get to the bean id.

@spring-projects-issues spring-projects-issues added status: declined type: enhancement in: web labels Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: web status: declined type: enhancement
None yet

No branches or pull requests

2 participants