加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

找不到404:Angular 2无法与Spring Rest API对话

发布时间:2020-12-15 01:46:33 所属栏目:大数据 来源:网络整理
导读:我在内存数据库中关注了Angular 2的英雄之旅教程.然后我创建了一个Spring后端来提供数据,并希望将Angular2与Spring的Rest API集成. 在Tour of Hero中,我只更改了hero.service.ts中的一行代码: /* private heroesUrl = 'app/heroes'; */private heroesUrl =

我在内存数据库中关注了Angular 2的英雄之旅教程.然后我创建了一个Spring后端来提供数据,并希望将Angular2与Spring的Rest API集成.

在Tour of Hero中,我只更改了hero.service.ts中的一行代码:

/* private heroesUrl = 'app/heroes'; */
private heroesUrl = 'http://localhost:8080/api/hero/all';

我更改的链接是Spring服务端点,如果我在浏览器中键入链??接,它将返回JSON数据:[{“id”:1,“name”:“test”}].

但是,我在英雄之旅中遇到错误:

EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: null

它看起来像localhost的spring端点:在localhost:3000上运行的Angular应用程序找不到8080.可能是什么问题?

最佳答案
这是前一段时间被问到的,但可能有人发现它很有用.

从package.json中删除以下依赖项:

"angular-in-memory-web-api": "~0.2.4",

将其从node_modules目录中删除,删除所有InMemoryWebApiModule和InMemoryWebApiModule以及与InMemoryDataService相关的代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读