Spring中通过增加的接口会被明确定义的接口覆盖

比如我们在Spring工程中定义了如下的API接口:

@RestController
public class TestController {
    @GetMapping("/httpProxy/ip")
    public Mono<JsonV2> httpProxyTest() {
        return Mono.just(new JsonV2<>(CodeMessage.OK, "", "adad"));
    }
}

但是我们同时通过动态的形式增加同样的接口:

import org.springframework.web.reactive.handler.AbstractHandlerMapping;
public class RoutePredicateHandlerMapping extends AbstractHandlerMapping {
  @Override
    public Mono<?> getHandlerInternal(final ServerWebExchange exchange) {
        exchange.getAttributes().put(GATEWAY_HANDLER_MAPPER_ATTR, getClass().getSimpleName());
        return lookupRoute(exchange)
                .flatMap((Function<Route, Mono<?>>) r -> {
                    logger.info("Mapping [" + buildRequestDesc(exchange) + "] to " + r);
                    exchange.getAttributes().put(GATEWAY_ROUTE_ATTR, r);
                    return Mono.just(webHandler);
                }).switchIfEmpty(Mono.empty().then(Mono.fromRunnable(() -> {
                    logger.info("No RouteDefinition found for [" + buildRequestDesc(exchange) + "]");
                })));
    }
}

此时在去访问/httpProxy/ip接口的话,其实访问的是上面我们通过@GetMapping("/httpProxy/ip")定义的。

本文版权归作者所有,禁止一切形式的转载,复制等操作
赞赏

微信赞赏支付宝赞赏

发表评论

电子邮件地址不会被公开。 必填项已用*标注