【问题标题】:Spring Boot 1.5.6 doesn't find index.htmlSpring Boot 1.5.6 找不到 index.html
【发布时间】:2018-03-09 04:43:58
【问题描述】:

我正在尝试将 index.html 连接到我的 Spring Boot 应用程序以使 localhost:8080 返回它。

我已经尝试了各种方法,我总是得到 404。 这是我的 application.properties 的一部分

server.context-path=/
spring.mvc.static-path-pattern=/resources/**
spring.resources.add-mappings=true

index.html 位于 src/main/resources/static 目录中。将 Apache CXF 用于 REST API 会对其产生某种影响吗?

【问题讨论】:

  • 你能发布你的控制器吗?
  • 从您的属性中删除 spring.mvc.static-path-pattern=/resources/**
  • @georgesvan 我没有 mvc 控制器
  • 它没有帮助@JBNizet
  • 如果你按照@JBNizet 所说的去做,你的 index.html 应该可以通过locahost:8080/index.html 访问。使用您的原始配置,它应该可以通过localhost:8080/resources/index.html 访问。

标签: java spring


【解决方案1】:
  • 删除此属性,您不需要它们。
  • 确保您在任何地方都没有 @EnableWebMvc 注释。
  • 如果你从 jar 运行你的应用程序,你应该已经在你的 pom 中配置了 spring-boot-maven-plugin。

  • 如果您从 IDE 运行应用程序,请尝试重建您的项目。

    很难说哪里出了问题。如果没有任何帮助,您应该从以下位置开始一个新项目:https://start.spring.io/ 如果它也不起作用,那么我们应该在其他地方寻找问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-16
    • 1970-01-01
    • 1970-01-01
    • 2017-05-01
    • 2016-11-21
    • 2021-11-07
    • 1970-01-01
    • 2020-07-31
    相关资源
    最近更新 更多