Angular 2 HTTP GET 404 Not Found for URL

前端 未结 3 1299
再見小時候
再見小時候 2020-12-08 21:02

I am trying to integrate Angular 2 application with Java Spring Boot backend. For the moment, I place my Angular 2 files under src/main/resources/static (meanin

3条回答
  •  悲&欢浪女
    2020-12-08 21:46

    The reason of this error was that I used Angular Tour of Heroes applcation as a basis for mine, and I did not remove the dependency

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

    and InMemoryWebApiModule from app.module.ts. Because of this all requests were intercepted by InMemoryWebApiModule (despite I did not call it directly as described in Tour of Heroes Tutorial), that's why I did not see any XMLHttpRequests in 'Network' tab of the browser debugger.

    After I have removed the dependency from package.json and node_modules directory, it started working normally, however, I had to change the service code to parse Json directly to TypeScript objects like this:

    getLanguages(): Promise {
        return this.http.get(this.langUrl)
            .toPromise()
            .then(response => response.json() as Language[])
            .catch(this.handleError);
    }
    

    This is a newbie mistake, but I hope this post will save a couple of hours of research to someone.

提交回复
热议问题