Spring Boot Webflux(反应式web应用程序)未在文件系统上提供静态内容



问题

当按照弹簧套2.4.2参考指南第4.7.2节"静态内容"中的详细说明设置spring.web.resources.static-locations配置时,未找到内容。

复制步骤

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

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

    导出SERVER_PORT=8084export SPRING_WEB_RESOURCES_STATICLOCATIONS=文件:C:\mydev\staticlocalmvn弹簧引导:运行

  3. 打开http://localhost:8084,http://localhost:8084/或http://localhost:8084/index.html使用浏览器,您会得到白标签错误页面

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

export SPRING_RESOURCES_STATICLOCATIONS=file:C:\mydev\staticlocal

备选方案2:这是有效的通过选择Dependencies="Spring Web";在步骤1)中,并且如下设置配置spring.resources.static-locations成功打开静态文件:

export SPRING_RESOURCES_STATICLOCATIONS=file:C:\mydev\staticlocal

上面的问题源于用于执行场景的shell。请参阅中的详细信息https://github.com/spring-projects/spring-boot/issues/25397

Spring框架如文档所示工作:)

最新更新