Allow RoutePredicateHandlerMapping customization

Allow bean overriding and add a property to set the order.

spring.cloud.gateway.handler-mapping.order=1

Fixes gh-2469
This commit is contained in:
spencergibb
2021-12-21 12:15:28 -05:00
parent 70fac23df5
commit 26cff62bf4
3 changed files with 9 additions and 1 deletions

View File

@@ -251,6 +251,7 @@ public class GatewayAutoConfiguration {
}
@Bean
@ConditionalOnMissingBean
public RoutePredicateHandlerMapping routePredicateHandlerMapping(FilteringWebHandler webHandler,
RouteLocator routeLocator, GlobalCorsProperties globalCorsProperties, Environment environment) {
return new RoutePredicateHandlerMapping(webHandler, routeLocator, globalCorsProperties, environment);

View File

@@ -20,6 +20,7 @@ import java.util.function.Function;
import reactor.core.publisher.Mono;
import org.springframework.cloud.gateway.config.GatewayProperties;
import org.springframework.cloud.gateway.config.GlobalCorsProperties;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.route.RouteLocator;
@@ -55,7 +56,7 @@ public class RoutePredicateHandlerMapping extends AbstractHandlerMapping {
this.managementPort = getPortProperty(environment, "management.server.");
this.managementPortType = getManagementPortType(environment);
setOrder(1);
setOrder(environment.getProperty(GatewayProperties.PREFIX + ".handler-mapping.order", Integer.class, 1));
setCorsConfigurations(globalCorsProperties.getCorsConfigurations());
}

View File

@@ -359,6 +359,12 @@
"type": "java.lang.Boolean",
"description": "If global CORS config should be added to the URL handler.",
"defaultValue": "false"
},
{
"name": "spring.cloud.gateway.handler-mapping.order",
"type": "java.lang.Integer",
"description": "The order of RoutePredicateHandlerMapping.",
"defaultValue": "1"
}
]
}