5

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
  • 1,082
  • 2
  • 11
  • 27

3 Answers3

3

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

enter image description here

Kms
  • 1,082
  • 2
  • 11
  • 27
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
  • 2,292
  • 2
  • 10
  • 21
0

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

Take a look at Angular’s Proxing documentation

Luca Riccitelli
  • 364
  • 1
  • 4
  • 13