【问题标题】:spring boot serve angular弹簧靴服务角度
【发布时间】:2019-05-17 20:00:44
【问题描述】:

我无法使用 Spring boot 为我的 Angular 应用程序提供服务。

@RequestMapping("/home")
public String home() {
    return "index";
}

文件夹结构

resources > public > index.html

如果我去 localhost:8080/home 我得到这个错误:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing 
this as a fallback.

Mon Dec 17 13:30:33 CET 2018
There was an unexpected error (type=Internal Server Error, status=500).
Could not resolve view with name 'index' in servlet with name 'dispatcherServlet'

但是如果我直接去http://localhost:8080/index.html 它确实有效

如果我直接去http://localhost:8080 我会得到:

No mapping for GET /

【问题讨论】:

    标签: angular spring-boot


    【解决方案1】:

    您放置在 resources/public 下的文件用于静态托管文件 - 这是您放置 html 登录页面、css、图像和 JS 资源的地方 - 代码中不需要请求映射。

    您的代码示例应该只返回定义的字符串,但看不到其余代码,很难说出失败的原因。

    【讨论】:

    • 你需要什么额外的信息来帮助我解决这个问题?
    • 我修好了。我有第二个用@EnableWebMvc 注释的配置文件。我删除它后它开始工作了。
    猜你喜欢
    • 2023-03-29
    • 2018-08-09
    • 2020-08-06
    • 1970-01-01
    • 2017-12-22
    • 2018-02-14
    • 1970-01-01
    • 2019-05-03
    • 2021-04-20
    相关资源
    最近更新 更多