腌萝卜皮springcloudgateway⾃定义断⾔规则,以后缀结尾进⾏路由
因⼯作需要,需要使⽤springcloud gateway ,以.html结尾的进⾏路由进⾏websocket转发。gateway⾃带的8种路由规则都不能满⾜,故需要⾃定义断⾔规则。
⼀,新建⼀个路由断⾔⼯⼚ExtCheckRoutePredicateFactory
@Component
public class ExtCheckRoutePredicateFactory extends AbstractRoutePredicateFactory<ExtCheckRoutePredicateFactory.Config> {
public ExtCheckRoutePredicateFactory() {
super(Config.class);
}淘宝自动回复在哪里设置
一份礼物@Override
public Predicate<ServerWebExchange> apply(Config config) {
return new Predicate<ServerWebExchange>() {
@Override
public boolean test(ServerWebExchange rverWebExchange) {
String Request().getURI().toString();
dsWith(".html")){
return true;
}
return fal;
}
};
}
public static class Config{
private String name;
public String getName(){
return name;
中国古典十大名曲
}
public void tName(String name){
this.name=name;
}
}
}
如果以.html结尾,则匹配此路由
⼆,修改gateway配置
gateway:
普通话手抄报内容
routes:
- id: abc
uri: localhost:8080
predicates:
- name: ExtCheck
ExtCheck即是我们新建断⾔⼯⼚的前缀名,⾃动识别的。
这时运⾏发现,系统根本找不到我们⾃定义的断⾔类。
需要第三步
三,修改gateway源码,将⾃定义断⾔类加到系统 predicates⾥
观察蜗牛
@Bean
public RouteLocator routeDefinitionRouteLocator(GatewayProperties properties, List<GatewayFilterFactory> gatewayFilters,
List<RoutePredicateFactory> predicates,
考试总结500字RouteDefinitionLocator routeDefinitionLocator,正方体折纸
ConfigurationService configurationService) {
predicates.add(new ExtCheckRoutePredicateFactory());
return new RouteDefinitionRouteLocator(routeDefinitionLocator, predicates,
gatewayFilters, properties, configurationService);
}
再次运⾏,成功根据.html后缀转发,done!