Spring cloud zuul does not load static resources from spring boot applications

那年仲夏 提交于 2021-01-28 23:57:16

问题


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

application.properties file:

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

RoutingAndFilteringGatewayApplication class:

@EnableZuulProxy
@SpringBootApplication
public class RoutingAndFilteringGatewayApplication {

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

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

}

and the SimpleFilter class:

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;
  }

}

and this is the structure of looli application:

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

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.

NOTE

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.

I'm new to zull ;)

来源:https://stackoverflow.com/questions/62991711/spring-cloud-zuul-does-not-load-static-resources-from-spring-boot-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!