【问题标题】:Spring boot to always serve from index.htmlSpring Boot 始终从 index.html 提供服务
【发布时间】:2019-02-16 17:22:57
【问题描述】:

我用 angular-cli 创建了一个 spring boot 项目。输出的 jar 文件如下所示:

BOOT-INF
    |- classes
        |- com
        |- static
            |- index.html

现在,当我转到以下网址时

http://<ip>:<port>

我被重定向到http://&lt;ip&gt;:&lt;port&gt;/app1,因为在我的角度路由中,我将其配置为重定向。

但是当我尝试刷新 http://&lt;ip&gt;:&lt;port&gt;/app1 时,我得到了 404 not found。

【问题讨论】:

标签: angular spring-boot


【解决方案1】:

Spring Boot 会自动在以下位置 public/static/webapp 中检测到 index.html

如果您有任何控制器专门编写了这样的映射 -> @Requestmapping("/") 它将覆盖默认行为并且不会显示 index.html 除非您路由到 http:\\localhost:8080\index.html

您可能希望在此文件夹结构下创建它

src/main/resources/public/index.html

希望这会有所帮助!

【讨论】:

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