java - 无法使用 Spring Boot 提供静态 index.html

标签 java spring spring-mvc

我是 Spring 的新手,我发现它真的很难上手。我想提供静态 index.html,但它不起作用。 enter image description here

我用了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..

enter image description here

最佳答案

你能试试下面的方法吗:

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

关于java - 无法使用 Spring Boot 提供静态 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40008958/

相关文章:

java - 方面是否替代存储库?

java - Spring MVC WebApp : @schedule: java-sdk-http-connection-reaper : Failed to Stop

java - Spring Framework 过滤器,未注入(inject) bean

spring - 在spring mvc中修改请求URI

java - DataAccessException 与 SQLException

java - 一旦我们在 JBoss AS 中配置了数据源,我们是否应该将 JDBCDriver 添加到我们的 Maven 项目中的依赖项中?

java - 同一 servlet URL 的多个 URL 映射产生错误

java - 在其他物体前面 Swing 物体

java - 使用假 smtp 服务器生成 MailSendException

JAVA总是从执行jar的目录读取