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:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user