【问题标题】:Spring Boot with custom context path - Cannot access static web files具有自定义上下文路径的 Spring Boot - 无法访问静态 Web 文件
【发布时间】:2020-09-06 20:27:18
【问题描述】:

我有一个使用 ReactJs 作为前端库的 Spring Boot 应用程序 (2.2.6.RELEASE)。 我在 application.properties 中配置了一个自定义上下文路径和 spring.mvc 属性,如下所示:

server.servlet.context-path=/gui
spring.mvc.view.prefix: /static/dist/
spring.mvc.view.suffix: .html
spring.mvc.static-path-pattern=/static/**

Webpack 用于在 src/main/resources/static/dist 中构建包和 index.html。项目结构如下所示:

我需要能够从

访问 index.html

本地主机:8080/gui

使用这些设置,但由于某种原因它无法启动。但是,如果我尝试使用

localhost:8080/gui/static/dist/index.html

资源已到达。如何配置 Spring 以按照我的意愿提供资源?

【问题讨论】:

  • spring.resources.static-locations=classpath:/static/dist/
  • @OlehKurpiak 帮助了我。谢谢!

标签: java spring spring-boot spring-mvc


【解决方案1】:

@Oleh Kurpiak 的回答是正确的。使用 spring.resources.static-locations=classpath:/static/dist/ 有所帮助。

【讨论】:

    猜你喜欢
    • 2018-05-17
    • 2020-01-20
    • 2016-12-11
    • 2015-08-09
    • 2022-01-25
    • 1970-01-01
    • 2018-10-01
    • 2023-03-17
    • 1970-01-01
    相关资源
    最近更新 更多