错误:无法匹配任何路由。当我使用2个资源时

时间:2018-06-09 20:48:06

标签: spring angular spring-boot angular-ui-router

好。我需要使用2个不同的Spring Boot资源来响应我的Angular Frontend。

我的前端的第一项服务是:

import {Login} from "./login.model";
import {Observable} from "rxjs/Observable";

@Injectable()
export class LoginService {

   private LoginUrl = 'http://192.168.0.104:8080/login/verifyLogin';

   constructor(private http: HttpClient){}

   verifyLogin(login: Login):Observable<number>{
      return this.http.post<number>(this.LoginUrl,login);
   }
}

我正在使用此资源来响应请求:

package com.satelite.frotainteligente.resource;

import com.google.gson.Gson;
import com.satelite.frotainteligente.DTO.LoginDTO;
import java.net.URISyntaxException;

import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "http://192.168.0.104:4200")
@RestController
@RequestMapping("/login")
public class LoginResource {

   private Gson gson = new Gson();

   @PostMapping("/verifyLogin")
   public String verifyLogin(@RequestBody LoginDTO loginDTO) throws URISyntaxException {
      Long id = 125L;
      return gson.toJson(id);
   }
}

我的第二项服务是:

import {Injectable} from "@angular/core";
import {HttpClient} from "@angular/common/http";

import {Observable} from "rxjs/Observable";
import {User} from "./home.model";

@Injectable()
export class HomeService {

   private userUrl = 'http://192.168.0.104:8080/home/getUsuario';

   constructor(private http: HttpClient){}

   getUser(id: number):Observable<User>{
      return this.http.get<User>(this.userUrl+'/'+id);
  }
}

我的第二个资源:

package com.satelite.frotainteligente.resource;

import com.google.gson.Gson;
import com.satelite.frotainteligente.DTO.UserDTO;
import org.springframework.web.bind.annotation.*;

@CrossOrigin(origins = "http://192.168.0.104:4200")
@RestController
@RequestMapping("/home")
public class HomeResource {

   Gson gson = new Gson();

   @GetMapping(value = "/getUsuario/{id}")
   public @ResponseBody String getDisciplinas(@PathVariable Long id){

       UserDTO userDTO = new UserDTO();
       userDTO.setUser_id(1L);
       userDTO.setUser_name("Lucas");
       userDTO.setUser_type("Secretario");

       return gson.toJson(userDTO);
   }
}

当我从LoginService请求我的LoginResource时,一切正常。但是在下一次我用HomeService调用HomeResource但是控制台向我显示了这个错误:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'home'
Error: Cannot match any routes. URL Segment: 'home'
at ApplyRedirects.noMatchError (router.js:1765)
at CatchSubscriber.eval [as selector] (router.js:1730)
at CatchSubscriber.error (catchError.js:105)
at MapSubscriber.Subscriber._error (Subscriber.js:134)
at MapSubscriber.Subscriber.error (Subscriber.js:108)
at MapSubscriber.Subscriber._error (Subscriber.js:134)
at MapSubscriber.Subscriber.error (Subscriber.js:108)
at MapSubscriber.Subscriber._error (Subscriber.js:134)
at MapSubscriber.Subscriber.error (Subscriber.js:108)
at LastSubscriber.Subscriber._error (Subscriber.js:134)
at ApplyRedirects.noMatchError (router.js:1765)
at CatchSubscriber.eval [as selector] (router.js:1730)
at CatchSubscriber.error (catchError.js:105)
at MapSubscriber.Subscriber._error (Subscriber.js:134)
at MapSubscriber.Subscriber.error (Subscriber.js:108)
at MapSubscriber.Subscriber._error (Subscriber.js:134)
at MapSubscriber.Subscriber.error (Subscriber.js:108)
at MapSubscriber.Subscriber._error (Subscriber.js:134)
at MapSubscriber.Subscriber.error (Subscriber.js:108)
at LastSubscriber.Subscriber._error (Subscriber.js:134)
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at eval (zone.js:873)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4751)
at ZoneDelegate.invokeTask (zone.js:420)
at Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at ZoneTask.invokeTask [as invoke] (zone.js:500)
at invokeTask (zone.js:1540)

我正在使用Angular 5和Spring Boot Framework。这是什么?

0 个答案:

没有答案