Spring Zuul重定向不适用于外部网址

问题描述

请您告知为什么mu Zuul重定向不起作用。

application.properties

    spring.application.name=netflix-zuul-api-gateway-server

application.yml

   zuul:
  routes:
    google:
      path: /google/**
      url: https://www.google.com/
      stripPrefix: true

bootstrap.properties

management.endpoints.web.exposure.include=*
management.endpoint.routes.enabled=true
management.endpoint.filters.enabled=true
server.port=8765

NetflixZuulApiGatewayServerApplication

@SpringBootApplication
public class NetflixZuulApiGatewayServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(NetflixZuulApiGatewayServerApplication.class,args);
    }
    
    @Bean
    public Sampler defaultSampler(){
        return Sampler.ALWAYS_SAMPLE;
    }

ZuulLoggingFilter

@Component
public class ZuulLoggingFilter extends ZuulFilter{

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public boolean shouldFilter() {
        return true;
    }

    @Override
    public Object run() {
        HttpServletRequest request = 
                RequestContext.getCurrentContext().getRequest();
        logger.info("request -> {} request uri -> {}",request,request.getRequestURI());
        return null;
    }

    @Override
    public String filterType() {
        return "pre";
    }

    @Override
    public int filterOrder() {
        return 1;
    }
}

版本:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

来自http:// localhost:8765 / actuator / routes / details的响应:

{
"/google/**": {
"id": "google","fullPath": "/google/**","location": "https://www.google.com/","path": "/**","prefix": "/google","retryable": false,"customSensitiveHeaders": false,"prefixStripped": true
}
}

为http:// localhost:8765 / google / try获取404

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...