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