首页 > 解决方案 > Zuul 路径 - SpringBoot 检测到它虽然没有配置

问题描述

我遵循了Spring Cloud 文档中的示例,现在已经在我的application.yml

server:
  port: 18081
  servlet:
    context-path: /myPath/services
zuul:
  # don't add per default all services automatically to the Zuul server
  ignoredServices: '*'
  routes:
    mytest: 
      #path: /checkPath/**
      url: http://mytest.server.local/api/

和一个配置的过滤器:

public class PreFilter extends ZuulFilter {
 
  @Override
  public String filterType() {
    return "pre";
  }
 
  @Override
  public int filterOrder() {
    return 1;
  }
 
  @Override
  public boolean shouldFilter() {
    return true;
  }
 
  @Override
  public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
 
    System.out.println("Request Method : " + request.getMethod() + " Request URL : " + request.getRequestURL().toString());
    return null;
  }
}

当我测试时

http://localhost:18081/myPath/services/mytest/test

我希望这仅在path配置时才有效。如果我将其保留为上述(未注释),我会从 ZuulPreFilter 得到它被击中。我不会期望它,因为不应该找到路径。是否存在误解或我错过了配置中的某些内容?为什么路径完全被命中,因为.../checkPath2/...不会被检测到?

标签: spring-bootnetflix-zuul

解决方案


推荐阅读