【问题标题】:Spring Boot - Proper location for html filesSpring Boot - html文件的正确位置
【发布时间】:2016-07-06 10:04:29
【问题描述】:

我是 Spring Boot 新手,我正在尝试为我的项目添加一个简单的 html 页面 目前,我的项目结构如下:

已阅读以下内容: https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot

http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-static-content

以及 StackOverflow 中的其他答案,我希望在访问 http://localhost:8080/ 时看到 index.html 的内容

我可能会错过什么?

【问题讨论】:

    标签: java spring-boot


    【解决方案1】:

    由于SpringBoot项目中没有webapp,我们可以将html文件放在其中一个

    src/main/resources/resources/index.html
    src/main/resources/static/index.html 
    src/main/resources/public/index.html 
    

    记住上面的优先级从高到低。

    要检查您的文件,请在 eclipse 中运行主类并转到 http://localhost:8080/index.html

    【讨论】:

      【解决方案2】:

      首先在 Spring Boot 中提供文件的正确方法在 cannot find html pages with spring boot

      添加所需目录后,我尝试了 /services/login.html,其中“服务”是我的 Dispatcher servlet 的映射。 所以这里发生的事情是 Spring Boot 只会响应发送到 /services/* 的请求,即使这些请求指向控制器以外的东西。 我想这在 Spring Boot 的世界中是有道理的,但是当我在 Spring MVC 项目(没有 Spring Boot)中尝试相同时,我能够访问我简单地添加到我的 WEB-INF 目录中的简单 html 文件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-23
        • 1970-01-01
        • 1970-01-01
        • 2020-04-02
        • 1970-01-01
        • 1970-01-01
        • 2021-11-17
        • 1970-01-01
        相关资源
        最近更新 更多