spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Auto-configure HandlerMethodArgumentResolvers on AnnotatedControllerConfigurer

Open maxhov opened this issue 1 year ago • 6 comments

Add an AnnotatedControllerConfigurerCustomizer to provide a friendly API to modify the autoconfiguredAnnotatedControllerConfigurer. End users could provide HandlerMethodArgumentResolvers without having to override the entire AnnotatedControllerConfigurer bean.

This has been discussed in (amongst others) https://github.com/spring-projects/spring-graphql/issues/603, but there seems no way to customize the AnnotatedControllerConfigurer. This PR aims to improve the API for end users.

maxhov avatar Apr 17 '24 16:04 maxhov

I see that the build fails on a missing @since in the Javadoc. Which version should I use here? Is it probable that it will make it into 3.3.0 still?

maxhov avatar Apr 19 '24 18:04 maxhov

@maxhov I'm afraid we'll probably not get this into 3.3 since we just cut RC1, but feel free to use that as the @Since tag. We can fix it up later.

philwebb avatar Apr 19 '24 18:04 philwebb

Why not auto-configure HandlerMethodArgumentResolver beans on that component in the existing configuration? To me customizers are useful when lots of options exist and when applications want to contribute several.

bclozel avatar Apr 20 '24 07:04 bclozel

@bclozel I chose this approach because it is also used for GraphQlSourceBuilder via GraphQlSourceBuilderCustomizer and it seemed sensible to take the same approach.

maxhov avatar Apr 20 '24 08:04 maxhov

The org.springframework.graphql.execution.GraphQlSource.Builder not only configures many things, but also is the gateway to configuring the GraphQL engine itself. The AnnotatedControllerConfigurer has less options and in this case, the HandlerMethodArgumentResolver are ordered, which means AnnotatedControllerConfigurerCustomizer should be ordered themselves or a single AnnotatedControllerConfigurerCustomizer should add all argument resolvers.

I think that as a first step, we should consider HandlerMethodArgumentResolver beans and set them on the configurer in an ordered fashion. I think we're too late in the cycle to consider this feature now.

bclozel avatar Apr 21 '24 17:04 bclozel

@bclozel I am not sure I understand. Registering either HandlerMethodArgumentResolver or AnnotatedControllerConfigurerCustomizer beans both need to be explicitely ordered via @Order/Ordered at the bean declaration, so which bean is defined would not really matter for that purpose?

Maybe exposing more methods on the AnnotatedControllerConfigurer API is not desirable at this moment, I can change the implementation to accepting HandlerMethodArgumentResolver beans and registering them. Let me know if you are open to that, then I will change the implementation as such. I understand that for 3.3 this may be too late.

maxhov avatar Apr 22 '24 10:04 maxhov

Maybe exposing more methods on the AnnotatedControllerConfigurer API is not desirable at this moment, I can change the implementation to accepting HandlerMethodArgumentResolver beans and registering them. Let me know if you are open to that, then I will change the implementation as such. I understand that for 3.3 this may be too late.

@maxhov Yes please! Let us know if you have some time for this or we will take care of it.

bclozel avatar Jul 20 '24 11:07 bclozel

@maxhov Yes please! Let us know if you have some time for this or we will take care of it.

@bclozel I updated the implementation as such.

maxhov avatar Jul 20 '24 13:07 maxhov

Thanks @maxhov for your contribution, this will be released with our next milestone.

bclozel avatar Jul 23 '24 15:07 bclozel