3

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

Kms
  • 891
  • 2
  • 7
  • 22

3 Answers3

2

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

enter image description here

Kms
  • 891
  • 2
  • 7
  • 22
1

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 .

George
  • 1,323
  • 1
  • 7
  • 16
0

The best solution is to configure Angular to proxying call to the backend.

Take a look at Angular’s Proxing documentation

Luca Riccitelli
  • 318
  • 1
  • 3
  • 12