If you have this Error , when you are trying to consume an API using Angular and Spring

Access to XMLHttpRequest at 'http://localhost:8080/client/all' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

The solution is :

Jusd add the annotation @crossorigin in your RestController to allow your frontend consuming the API

@CrossOrigin // you can add (origins = "http://localhost:4200") to set only one source

Read also : Solution for : net::ERR_CONNECTION_REFUSED in Angular

Laisser un commentaire