Spring WebFlux and Spring MVC introduced functional style configuration models for HTTP endpoints in 2017.
@Bean
RouterFunction<ServerResponse> myMvcRouterFunction() {
return route()
.GET("/**", new HandlerFunction<ServerResponse>() {
@Override
public ServerResponse handle(ServerRequest request) throws Exception {
return ServerResponse.ok().body("hello world");
}
})
.build();
}
obviously, you wouldn't normally write that code out long hand. You'd use a lambda.
@Bean
RouterFunction<ServerResponse> myMvcRouterFunction() {
return route()
.GET("/**", _ -> ServerResponse.ok().body("hello world"))
.build();
}
That's taken from a Spring MVC application, though it's basically the same in Spring Webflux.
However, as far as I can tell, it's not possible to benefit from the various parameter/return value/argument resolvers for Spring MVC/Spring Webflux controllers in this model. This means things like Spring Security's @RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient oac are inaccessible.
For at leas the argument / parameter resolvers, it might be nice to provide a singleton.
I am hoping you'd consider exposing those as proxied singletons, sort of like Spring Framework's EntityManager, so that I could inject a singleton bean (OAuth2AuthorizedClient), but behind the scenes it would be scoped to the currently authenticated user. This might even be as simple as a request scoped bean, though I feel (perhaps irrationally) that that's less ideal than a simple facade (or even a proxy) that just sources the right value for the currently authenticated user.
Spring WebFlux and Spring MVC introduced functional style configuration models for HTTP endpoints in 2017.
obviously, you wouldn't normally write that code out long hand. You'd use a lambda.
That's taken from a Spring MVC application, though it's basically the same in Spring Webflux.
However, as far as I can tell, it's not possible to benefit from the various parameter/return value/argument resolvers for Spring MVC/Spring Webflux controllers in this model. This means things like Spring Security's
@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient oacare inaccessible.For at leas the argument / parameter resolvers, it might be nice to provide a singleton.
I am hoping you'd consider exposing those as proxied singletons, sort of like Spring Framework's
EntityManager, so that I could inject a singleton bean (OAuth2AuthorizedClient), but behind the scenes it would be scoped to the currently authenticated user. This might even be as simple as arequestscoped bean, though I feel (perhaps irrationally) that that's less ideal than a simple facade (or even a proxy) that just sources the right value for the currently authenticated user.