diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java index 68786ea928..a580148f67 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java @@ -18,13 +18,11 @@ package org.springframework.web.server.adapter; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.http.codec.ServerCodecConfigurer; @@ -158,12 +156,16 @@ public final class WebHttpHandlerBuilder { WebHttpHandlerBuilder builder = new WebHttpHandlerBuilder( context.getBean(WEB_HANDLER_BEAN_NAME, WebHandler.class), context); - // Autowire lists for @Bean + @Order - - SortedBeanContainer container = new SortedBeanContainer(); - context.getAutowireCapableBeanFactory().autowireBean(container); - builder.filters(filters -> filters.addAll(container.getFilters())); - builder.exceptionHandlers(handlers -> handlers.addAll(container.getExceptionHandlers())); + List webFilters = context + .getBeanProvider(WebFilter.class) + .orderedStream() + .collect(Collectors.toList()); + builder.filters(filters -> filters.addAll(webFilters)); + List exceptionHandlers = context + .getBeanProvider(WebExceptionHandler.class) + .orderedStream() + .collect(Collectors.toList()); + builder.exceptionHandlers(handlers -> handlers.addAll(exceptionHandlers)); try { builder.sessionManager( @@ -389,30 +391,4 @@ public final class WebHttpHandlerBuilder { return new WebHttpHandlerBuilder(this); } - - private static class SortedBeanContainer { - - private List filters = Collections.emptyList(); - - private List exceptionHandlers = Collections.emptyList(); - - @Autowired(required = false) - public void setFilters(List filters) { - this.filters = filters; - } - - public List getFilters() { - return this.filters; - } - - @Autowired(required = false) - public void setExceptionHandlers(List exceptionHandlers) { - this.exceptionHandlers = exceptionHandlers; - } - - public List getExceptionHandlers() { - return this.exceptionHandlers; - } - } - } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java index 54774f7831..806ff8ee68 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java @@ -18,11 +18,11 @@ package org.springframework.web.reactive.function.server.support; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import reactor.core.publisher.Mono; import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.lang.Nullable; @@ -111,9 +111,11 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini } private List> routerFunctions() { - SortedRouterFunctionsContainer container = new SortedRouterFunctionsContainer(); - obtainApplicationContext().getAutowireCapableBeanFactory().autowireBean(container); - List> functions = container.routerFunctions; + List> functions = this.getApplicationContext() + .getBeanProvider(RouterFunction.class) + .orderedStream() + .map(router -> (RouterFunction)router) + .collect(Collectors.toList()); return (!CollectionUtils.isEmpty(functions) ? functions : Collections.emptyList()); } @@ -148,16 +150,4 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini } } - - private static class SortedRouterFunctionsContainer { - - @Nullable - private List> routerFunctions; - - @Autowired(required = false) - public void setRouterFunctions(List> routerFunctions) { - this.routerFunctions = routerFunctions; - } - } - }