我正在学习网络流量,我想知道如何使用网络流量在MicroService上提供静态内容,但我没有找到这样做的信息。
发布于 2017-04-27 22:39:28
尝尝这个
RouterFunction router = resources("/**", new ClassPathResource("public/"));
更新:在从外部访问它时不要忘记在URL中指定静态文件的名称,比如localhost:8080/index.html
发布于 2018-04-20 08:30:45
胡安·麦地那是对的。我只想让它更清楚,并提供一个参考链接。
实际上,您只需添加一个RouterFunction bean来处理静态资源。您不必实现自己的RouterFunction,因为RouterFunctions.resources("/**", new ClassPathResource("static/"));
给出了您想要的东西。
我所做的就是添加这段代码:
@Bean
RouterFunction<ServerResponse> staticResourceRouter(){
return RouterFunctions.resources("/**", new ClassPathResource("static/"));
}
任何未重新记录的请求都将落入静态路由器。
发布于 2017-06-12 12:29:47
Spring &公共静态Web资源配置
public-web-resources
文件夹:
./src/main/public-web-资源application.yaml
:
web-应用程序-类型:“反应性”public.webFlux.static-path-模式:"/app/**“public.resources.静态-位置:"classpath:/public-web-resources/”pom.xml
maven-resources-plugin3.0.1复制-资源验证复制资源src/main/public-web-资源真${basedir}/target/classes/public-web-resourcesorg.springframework.boot spring-启动-maven-插件2.0.0.BUILD-快照https://stackoverflow.com/questions/43622053
复制相似问题