Make sure the WebMvcRegistrations' and WebFluxRegistrations' getter methods are not called twice thus avoiding possible throw away construction of the returned objects in case the getter methods are implemented such that they construct a new object on each invocation.

Comment From: pivotal-issuemaster

@mruzicka Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

Comment From: pivotal-issuemaster

@mruzicka Thank you for signing the Contributor License Agreement!

Comment From: wilkinsona

Thanks for the proposal, @mruzicka. This looks to me like a good change to make. Out of interest, have you seen the repeated invocations of the getters cause a problem in the real world or is this more theoretical?

Comment From: wilkinsona

If/when we merge this, we should make a similar change to EnableWebFluxConfiguration when it's calling getters on WebFluxRegistrations.

Comment From: mruzicka

Thanks for the proposal, @mruzicka. This looks to me like a good change to make. Out of interest, have you seen the repeated invocations of the getters cause a problem in the real world or is this more theoretical?

Hi @wilkinsona, I noticed it while evaluating the openapi-generator in a demo project. I happened to need a custom implementation of RequestMappingHandlerAdapter (to prioritize a custom HandlerMethodArgumentResolvers before the standard ones). I used a trivial WebMvcRegistrations implementation to create one (on each invocation of the respective getter method) and noticed that it was being created twice. Did it have a measurable impact? No, but it might have if the creation of the custom RequestMappingHandlerAdapter was expensive.

I've added similar changes to the EnableWebFluxConfiguration.

Comment From: wilkinsona

@mruzicka Thanks very much for making your first contribution to Spring Boot. The proposed changes have been merged into 2.3 and 2.4.

Comment From: mruzicka

Thank you!