Spring Cloud zuul 不会从 Spring Boot 应用程序加载静态资源 [英] Spring cloud zuul does not load static resources from spring boot applications

查看:111
本文介绍了Spring Cloud zuul 不会从 Spring Boot 应用程序加载静态资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a simple gateway that implemented with zuul as you can see below:

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 错误.

Now, when i enter localhost:8070/looli in the browser it loads index.html, but get 404 error for all of static resources under dist directory.

注意

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

After i googled my problem, i found this question on SO and also checked his solution by creating looli folder under resources, but didn't affect.

我是 zull 的新手 ;)

I'm new to zull ;)

推荐答案

Whatch this post: CSS 未在 Spring Boot 中加载,您需要将静态内容放入模板文件夹

Whatch this post: CSS not loading in Spring Boot, you need put you static content into templates folder

这篇关于Spring Cloud zuul 不会从 Spring Boot 应用程序加载静态资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆