Browse Source

Allow RouterFunction parameterized with different types

This commit allows *any* type of `RouterFunction` to be injected in the
WebFlux.fn auto-configuration; previously the `RouterFunction<T>` would
restrict injected beans to a single parameterized type.

Doing requires using the `RouterFunction.andOther` method to collect
them.

Fixes gh-9181
pull/9151/merge
Brian Clozel 9 years ago
parent
commit
d7ba7ecc48
  1. 7
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java

7
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/HttpHandlerAutoConfiguration.java

@ -36,7 +36,6 @@ import org.springframework.web.reactive.DispatcherHandler;
import org.springframework.web.reactive.function.server.HandlerStrategies; import org.springframework.web.reactive.function.server.HandlerStrategies;
import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.reactive.result.view.ViewResolver; import org.springframework.web.reactive.result.view.ViewResolver;
import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebHandler; import org.springframework.web.server.WebHandler;
@ -101,10 +100,10 @@ public class HttpHandlerAutoConfiguration {
} }
@Bean @Bean
public <T extends ServerResponse> HttpHandler httpHandler(List<RouterFunction<T>> routerFunctions) { public HttpHandler httpHandler(List<RouterFunction<?>> routerFunctions) {
routerFunctions.sort(new AnnotationAwareOrderComparator()); routerFunctions.sort(new AnnotationAwareOrderComparator());
RouterFunction<T> routerFunction = routerFunctions.stream() RouterFunction<?> routerFunction = routerFunctions.stream()
.reduce(RouterFunction::and).get(); .reduce(RouterFunction::andOther).get();
if (this.handlerStrategiesBuilder == null) { if (this.handlerStrategiesBuilder == null) {
this.handlerStrategiesBuilder = HandlerStrategies.builder(); this.handlerStrategiesBuilder = HandlerStrategies.builder();
} }

Loading…
Cancel
Save