Skip to content

Commit 26cff62

Browse files
committed
Allow RoutePredicateHandlerMapping customization
Allow bean overriding and add a property to set the order. spring.cloud.gateway.handler-mapping.order=1 Fixes gh-2469
1 parent 70fac23 commit 26cff62

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public GlobalCorsProperties globalCorsProperties() {
251251
}
252252

253253
@Bean
254+
@ConditionalOnMissingBean
254255
public RoutePredicateHandlerMapping routePredicateHandlerMapping(FilteringWebHandler webHandler,
255256
RouteLocator routeLocator, GlobalCorsProperties globalCorsProperties, Environment environment) {
256257
return new RoutePredicateHandlerMapping(webHandler, routeLocator, globalCorsProperties, environment);

spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/handler/RoutePredicateHandlerMapping.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import reactor.core.publisher.Mono;
2222

23+
import org.springframework.cloud.gateway.config.GatewayProperties;
2324
import org.springframework.cloud.gateway.config.GlobalCorsProperties;
2425
import org.springframework.cloud.gateway.route.Route;
2526
import org.springframework.cloud.gateway.route.RouteLocator;
@@ -55,7 +56,7 @@ public RoutePredicateHandlerMapping(FilteringWebHandler webHandler, RouteLocator
5556

5657
this.managementPort = getPortProperty(environment, "management.server.");
5758
this.managementPortType = getManagementPortType(environment);
58-
setOrder(1);
59+
setOrder(environment.getProperty(GatewayProperties.PREFIX + ".handler-mapping.order", Integer.class, 1));
5960
setCorsConfigurations(globalCorsProperties.getCorsConfigurations());
6061
}
6162

spring-cloud-gateway-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@
359359
"type": "java.lang.Boolean",
360360
"description": "If global CORS config should be added to the URL handler.",
361361
"defaultValue": "false"
362+
},
363+
{
364+
"name": "spring.cloud.gateway.handler-mapping.order",
365+
"type": "java.lang.Integer",
366+
"description": "The order of RoutePredicateHandlerMapping.",
367+
"defaultValue": "1"
362368
}
363369
]
364370
}

0 commit comments

Comments
 (0)