@CrossOrigin(allowCredentials = "true")
时间: 2023-12-08 11:02:57 浏览: 78
@CrossOrigin(allowCredentials = "true")是一个注解,用于在Spring Boot中处理跨域请求时设置是否允许携带cookie。根据引用\[1\]和引用\[2\]的内容,如果使用的是Spring Boot 2.0及以后的版本,默认情况下allowCredentials属性的值为false,这意味着返回的响应头AccessControlAllowCredentials属性值也为false,如果客户端携带cookie的请求将无法进行跨域访问。因此,需要手动在注解中设置allowCredentials为true,即@CrossOrigin(allowCredentials = "true"),以允许跨域请求携带cookie。这种方式适用于只有一两个REST接口需要跨域或者没有网关的情况下,修改影响较小。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* [解决使用@CrossOrigin注解后仍然不能跨域访问的问题](https://blog.csdn.net/qq_39387856/article/details/96877535)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [@CrossOrigin注解失效问题](https://blog.csdn.net/qq_44145781/article/details/122917255)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [Spring Cloud配置跨域访问的五种方案](https://blog.csdn.net/MasonCen/article/details/106098549)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文