Getting below error when tried to call spring rest end point in angular.
Origin http://localhost:4200 has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
CodePudding user response:
Solution: Add @CrossOrigin("*") annotation on top of respective Controller Class.
CodePudding user response:
By using CrossOrigin("*") your accepting all domains.
which is not recommended and here is why .
Using @CrossOrigin(origins = "http://localhost:4200")
will have the same effect for your situation and would only accept localhost:4200 .
CodePudding user response:
The best solution is to configure Angular to proxying call to the backend.
Take a look at Angular’s Proxing documentation


