找不到404:Angular 2无法与Spring Rest API通讯 [英] 404 Not Found: Angular 2 can't talk to Spring Rest API
问题描述
我在内存数据库中遵循了Angular 2的英雄之旅"教程.然后,我创建了一个Spring后端来提供数据,并希望将Angular2与Spring的Rest API集成.
I followed Angular 2's Tour of Hero tutorial with in memory database. Then I created a Spring backend to supply data and want to integrate Angular2 with Spring's Rest API.
在《英雄之旅》中,我只更改了hero.service.ts中的一行代码:
In Tour of Hero I only changed one line of code in hero.service.ts:
/* private heroesUrl = 'app/heroes'; */
private heroesUrl = 'http://localhost:8080/api/hero/all';
我更改为的链接是Spring服务终结点,如果我在浏览器中键入该链接,它将返回JSON数据: [{"id":1,"name":"test"}] 代码>.
The link I changed to is the the Spring service endpoint, if I type the link in browser, it returns JSON data: [{"id":1,"name":"test"}]
.
但是,我在《英雄之旅》中遇到错误:
However, I am getting error in Tour of Hero:
EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: null
运行在 localhost:3000
上的Angular应用程序似乎找不到 localhost:8080
的spring终结点.可能是什么问题?
It looks like the spring endpoint of localhost:8080
is not found by Angular application running on localhost:3000
. What could be the issue?
推荐答案
这是在不久前问到的,但可能有人觉得它有用.
This was asked a while ago, but probably someone finds it useful.
从package.json中删除以下依赖项:
Delete the following dependency from your package.json:
"angular-in-memory-web-api": "~0.2.4",
从 node_modules
目录中删除它,删除所有与 InMemoryWebApiModule
和 InMemoryWebApiModule
和 InMemoryDataService
相关的代码.
Remove it from node_modules
directory, delete all InMemoryWebApiModule
and InMemoryWebApiModule
and InMemoryDataService
-related code.
这篇关于找不到404:Angular 2无法与Spring Rest API通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!