【问题标题】:Spring Boot Webflux (reactive web app) not serving static content on file systemSpring Boot Webflux(反应式 Web 应用程序)不在文件系统上提供静态内容
【发布时间】:2021-05-05 16:08:36
【问题描述】:

问题

按照4.7.2 Static Content of the spring boot 2.4.2 reference guide 部分的详细说明设置spring.web.resources.static-locations 配置时,找不到内容。

复制步骤

  1. 打开Spring Initialzr,选择Project=Maven项目,Language=Java,Spring Boot=2.4.2,Packaging=Jar,Java=8,Dependencies=Spring Reactive Web

  2. 使用环境变量运行生成的应用程序,下面的路径指向包含 index.html 文件的有效文件夹

    导出 SERVER_PORT=8084 导出 SPRING_WEB_RESOURCES_STATICLOCATIONS=file:C:\mydev\staticlocal mvn spring-boot:run

  3. 用浏览器打开 http://localhost:8084 , http://localhost:8084/ 或 http://localhost:8084/index.html 你会得到一个Whitelabel Error Page

备选方案 1 通过在步骤2)中设置配置spring.resources.static-locations重复上述步骤同样将无法打开链接的静态文件:

export SPRING_RESOURCES_STATICLOCATIONS=file:C:\\mydev\\staticlocal

备选方案 2:可行 通过在步骤 1) 中选择 Dependencies="Spring Web" 重复这些步骤并设置配置 spring.resources.static-locations 如下将成功打开静态文件:

export SPRING_RESOURCES_STATICLOCATIONS=file:C:\\mydev\\staticlocal

【问题讨论】:

    标签: spring spring-boot spring-webflux


    【解决方案1】:

    上述问题源于用于执行场景的 shell。详情见https://github.com/spring-projects/spring-boot/issues/25397

    Spring 框架按文档说明工作 :)

    【讨论】:

      猜你喜欢
      • 2015-05-24
      • 2019-02-13
      • 2017-03-01
      • 2014-09-15
      • 2022-01-02
      • 2018-12-28
      • 1970-01-01
      • 2015-06-04
      • 2019-03-30
      相关资源
      最近更新 更多