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

zhi*_*eiw 5 rest spring angular

我在内存数据库中关注了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';
Run Code Online (Sandbox Code Playgroud)

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

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

EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: null
Run Code Online (Sandbox Code Playgroud)

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

mp_*_*oki 3

不久前有人问过这个问题,但可能有人觉得它很有用。

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

"angular-in-memory-web-api": "~0.2.4",
Run Code Online (Sandbox Code Playgroud)

从目录中删除它node_modules,删除所有InMemoryWebApiModuleInMemoryWebApiModuleInMemoryDataService相关的代码。