【问题标题】:Spring cloud zuul does not load static resources from spring boot applicationsSpring Cloud zuul 不会从 Spring Boot 应用中加载静态资源
【发布时间】:2020-11-09 11:42:14
【问题描述】:

我有一个使用 zuul 实现的简单网关,如下所示:

application.properties文件:

zuul.routes.looli.url=http://localhost:8082
ribbon.eureka.enabled=false
server.port=8070

RoutingAndFilteringGatewayApplication类:

@EnableZuulProxy
@SpringBootApplication
public class RoutingAndFilteringGatewayApplication {

    public static void main(String[] args) {
        SpringApplication.run(RoutingAndFilteringGatewayApplication.class, args);
    }

    @Bean
    public SimpleFilter simpleFilter() {
        return new SimpleFilter();
    }

}

还有SimpleFilter 类:

public class SimpleFilter extends ZuulFilter {

  private static Logger log = LoggerFactory.getLogger(SimpleFilter.class);

  @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();

    log.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));

    return null;
  }

}

这是 looli 应用程序的结构:

  src
    |_main
          |_java
          |_resources
          |_webapp
                 |_dist
                 |     |_js
                 |     |_css
                 |     |_img
                 |
                 |_index.html

现在,当我在浏览器中输入 localhost:8070/looli 时,它会加载 index.html,但是对于 dist 目录下的所有静态资源都会出现 404 错误。

注意

在我用谷歌搜索我的问题后,我在 SO 上找到了this 问题,并通过在 resources 下创建 looli 文件夹检查了他的解决方案,但没有影响。

我是 zull 的新手 ;)

【问题讨论】:

    标签: java spring spring-boot reverse-proxy netflix-zuul


    【解决方案1】:

    Whatch 这个帖子:CSS not loading in Spring Boot,你需要把你的静态内容放到模板文件夹中

    【讨论】:

      猜你喜欢
      • 2015-03-08
      • 2017-07-26
      • 2016-10-01
      • 2017-02-21
      • 2014-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-07
      相关资源
      最近更新 更多