網站首頁 編程語言 正文
新建java類:復制下面即可、注意包名和類名
package com.example.start.CORSConfig;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CORSConfiguration implements WebMvcConfigurer {
static final String ORIGINS[] = new String[] { "GET", "POST", "PUT", "DELETE" };
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**") // 所有的當前站點的請求地址,都支持跨域訪問。
.allowedOriginPatterns("*") // 所有的外部域都可跨域訪問。 如果是localhost則很難配置,因為在跨域請求的時候,外部域的解析可能是localhost、127.0.0.1、主機名
.allowCredentials(true) // 是否支持跨域用戶憑證
.allowedMethods(ORIGINS) // 當前站點支持的跨域請求類型是什么
.maxAge(3600); // 超時時長設置為1小時。 時間單位是秒。
}
}
原文鏈接:https://blog.csdn.net/qq_37061571/article/details/121906043
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-10-26 Jira?任務管理系統項目總結講解_React
- 2022-08-16 Hive常用日期格式轉換語法_數據庫其它
- 2023-04-18 go實現服務優雅關閉的示例_Golang
- 2022-05-11 xml中符號轉化
- 2022-11-08 go語言Pflag?Viper?Cobra?核心功能使用介紹_Golang
- 2021-12-02 如何解決用ESLint驗證導致報錯的問題
- 2022-08-10 .Net使用Cancellation?Framework取消并行任務_實用技巧
- 2022-05-21 C++多線程互斥鎖和條件變量的詳解_C 語言
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支