【问题标题】:Can't serve static index.html with Spring Boot无法使用 Spring Boot 提供静态 index.html
【发布时间】:2017-02-21 20:48:14
【问题描述】:

我是 Spring 新手,我发现很难进入它。我想提供静态 index.html 但它不起作用。

我使用了this 教程,但无法通过以下方式访问 index.html: http://localhost:8080/http://localhost:8080/src/main/public/index.html

IndexHtmlController:

package de.phip1611.springboot_test_1;

import org.springframework.stereotype.Controller;

@Controller
public class IndexHtmlController {}
// due to https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot
// this should be enough..

【问题讨论】:

  • server.contextPath 属性的值是多少?
  • 那是什么?未设置

标签: java spring spring-mvc


【解决方案1】:

你可以试试下面的:

  1. index.html 移动到src/main/resources/static 文件夹
  2. 在spring boot的application.properties文件中,将server.contextPath设置为/。 (即server.contextPath=/

【讨论】:

    【解决方案2】:

    我在 src/main/resources/static 文件夹中有一个 html 文件,并在 application.yml 下面添加了它,但它对我也不起作用。在 tomcat 启动时,localhost:8080 显示 404,网页显示 whitelabel 错误。但是对于 localhost:8080/hello.html 我在检查时看到 200 响应代码,但网页上没有 html 内容。

    server:
      servlet:
        context-path: /
      port: 8080
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 2017-07-12
      • 2017-01-21
      • 2017-06-01
      • 1970-01-01
      • 2016-01-18
      相关资源
      最近更新 更多