Home > OS >  Origin http://localhost:4200 has been blocked by CORS policy error in browser when tried to call Spr
Origin http://localhost:4200 has been blocked by CORS policy error in browser when tried to call Spr

Time:01-06

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

Error Image: enter image description here

CodePudding user response:

Solution: Add @CrossOrigin("*") annotation on top of respective Controller Class.

enter image description here

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

  •  Tags:  
  • Related