当尝试以角度调用 Spring REST 端点时,来源 http://localhost:4200 已被浏览器中的 CORS 策略错误阻止

Kms*_*Kms 5 spring spring-boot

尝试以角度调用弹簧静止终点时出现以下错误。

Origin http://localhost:4200 has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
Run Code Online (Sandbox Code Playgroud)

错误图像: 在此输入图像描述

Kms*_*Kms 3

解决方案:在相应的控制器类顶部添加 @CrossOrigin("*") 注释。

在此输入图像描述