spring-boot - application.properties 中的 web.cors.allowed-origins 不允许特定 URL 的 CORS
问题描述
我正在尝试在整个应用程序中为“ http://localhost/4200 ”启用 CORS。由于我使用的是 Springboot 2 和一致。在它的文档中,我只需要在 application.properties 文件中添加这个属性:
management.endpoints.web.cors.allowed-origins=http://localhost:4200
但这不起作用。其次,由于我通过 restController 发出请求,出于测试目的,我尝试添加内联:
CrossOrigin(origins = "http://localhost:4401")
这也允许数据流通过 4401 端口。
解决方案
无法从 application.properties 文件设置 CORS 设置。属性 management.endpoints.web.cors.allowed-origins 与 Spring Actuator 相关。
如果您想使用特定端点的设置,您可以使用您在问题中提到的 @CrossOrigin 注释。
如果要为应用程序设置全局策略,可以添加配置类/bean 来设置 CORS 设置。请参阅:https ://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-cors
推荐阅读
- git - 在 OSX 中查找更新文件的进程
- java - 强制子类以自身为参数覆盖方法
- javascript - 获取对象数组中的所有对象
- docker - GCP 中 kubernetes 内同一节点上从 Pod 到 Pod 的通信
- android - android.support.v7.widget.AppCompatButton 无法实例化(使用自定义样式)
- c# - 在 C# 中计算 git blob 哈希
- python - Web Scraping:如何获取“href”链接并从中获取表格
- sql - 如何在 oracle developer 中执行程序?
- go - 具有多个通道的多个 goroutine 的死锁
- javascript - 我无法在 Express 服务器中加载我的静态 JS