Я новичок в Angular и Spring Boot и хочу разработать веб-приложение.
Я следовал учебному пособию, и теперь я в мертвой точке
Ссылка на учебник: https://developer.okta.com/blog/2018/08/22/basic-crud-angular-7-and-spring-boot-2?fbclid=IwAR2aR0Ku7oBhYM32zkxZGJXqStnRB1Lhg_K0pUO8XipZu2eiMs0ojikIY-Y
Я получаю эту ошибку от браузера, когда запускаю код.
Полагаю, что URL-адрес не совпадает.
Это код от Spring:
OfferController .java
@RestController
public class OfferController {
@Autowired
private OfferService offerService;
@CrossOrigin( origins= "http://localhost:4200" )
@GetMapping("/offers")
public List<Offer> getAllOffers() {
return offerService.getAllOffers();
}
}
OfferRepository.java
@RepositoryRestResource
@CrossOrigin(origins = "http://localhost:4200")
public interface OfferRepository extends JpaRepository<Offer, String>{}
И код от Angular:
export class OfferService {
constructor( private http: HttpClient) { }
getAll(): Observable<any> {
return this.http.get('//localhost:8080/offers');
}
}
И ошибка:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'offers'
Error: Cannot match any routes. URL Segment: 'offers'
at ApplyRedirects.push../node_modules/@angular/router/fesm5/router.js.ApplyRedirects.noMatchError (router.js:2469)
at CatchSubscriber.selector (router.js:2450)
at CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error (catchError.js:34)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error (Subscriber.js:80)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error (Subscriber.js:60)
at TapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/tap.js.TapSubscriber._error (tap.js:61)
at resolvePromise (zone.js:831)
at resolvePromise (zone.js:788)
at zone.js:892
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
at Object.onInvokeTask (core.js:16147)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
at drainMicroTaskQueue (zone.js:601)
Если я не ошибаюсь, это должно работать так: при обращении к http://localhost:4200 должны возвращаться данные с http://localhost:8080/offers.
Пожалуйста, помогите мне!