Ensure AsyncSupportConfigurer is created once
Now that we have two adapters that need access to the configurer, we need to save it in a field like others. See gh-25931
This commit is contained in:
@@ -253,6 +253,9 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
@Nullable
|
||||
private Map<String, CorsConfiguration> corsConfigurations;
|
||||
|
||||
@Nullable
|
||||
private AsyncSupportConfigurer asyncSupportConfigurer;
|
||||
|
||||
|
||||
/**
|
||||
* Set the Spring {@link ApplicationContext}, e.g. for resource loading.
|
||||
@@ -652,8 +655,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
adapter.setResponseBodyAdvice(Collections.singletonList(new JsonViewResponseBodyAdvice()));
|
||||
}
|
||||
|
||||
AsyncSupportConfigurer configurer = new AsyncSupportConfigurer();
|
||||
configureAsyncSupport(configurer);
|
||||
AsyncSupportConfigurer configurer = getAsyncSupportConfigurer();
|
||||
if (configurer.getTaskExecutor() != null) {
|
||||
adapter.setTaskExecutor(configurer.getTaskExecutor());
|
||||
}
|
||||
@@ -684,8 +686,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
public HandlerFunctionAdapter handlerFunctionAdapter() {
|
||||
HandlerFunctionAdapter adapter = new HandlerFunctionAdapter();
|
||||
|
||||
AsyncSupportConfigurer configurer = new AsyncSupportConfigurer();
|
||||
configureAsyncSupport(configurer);
|
||||
AsyncSupportConfigurer configurer = getAsyncSupportConfigurer();
|
||||
if (configurer.getTimeout() != null) {
|
||||
adapter.setAsyncRequestTimeout(configurer.getTimeout());
|
||||
}
|
||||
@@ -717,13 +718,6 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to configure asynchronous request processing options.
|
||||
* @see AsyncSupportConfigurer
|
||||
*/
|
||||
protected void configureAsyncSupport(AsyncSupportConfigurer configurer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link FormattingConversionService} for use with annotated controllers.
|
||||
* <p>See {@link #addFormatters} as an alternative to overriding this method.
|
||||
@@ -945,6 +939,26 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for building the {@link AsyncSupportConfigurer}.
|
||||
* Delegates to {@link #configureAsyncSupport(AsyncSupportConfigurer)}.
|
||||
* @since 5.3.2
|
||||
*/
|
||||
protected AsyncSupportConfigurer getAsyncSupportConfigurer() {
|
||||
if (this.asyncSupportConfigurer == null) {
|
||||
this.asyncSupportConfigurer = new AsyncSupportConfigurer();
|
||||
configureAsyncSupport(this.asyncSupportConfigurer);
|
||||
}
|
||||
return this.asyncSupportConfigurer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method to configure asynchronous request processing options.
|
||||
* @see AsyncSupportConfigurer
|
||||
*/
|
||||
protected void configureAsyncSupport(AsyncSupportConfigurer configurer) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of {@link CompositeUriComponentsContributor} for use with
|
||||
* {@link org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder}.
|
||||
|
||||
Reference in New Issue
Block a user