【发布时间】: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 配置时,找不到内容。
复制步骤
-
打开Spring Initialzr,选择Project=Maven项目,Language=Java,Spring Boot=2.4.2,Packaging=Jar,Java=8,Dependencies=Spring Reactive Web
-
使用环境变量运行生成的应用程序,下面的路径指向包含 index.html 文件的有效文件夹
导出 SERVER_PORT=8084 导出 SPRING_WEB_RESOURCES_STATICLOCATIONS=file:C:\mydev\staticlocal mvn spring-boot:run
-
用浏览器打开 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