Spring Boot全局支持CORS(跨源请求)
1 import org.springframework.context.annotation.Configuration; 2 import org.springframework.web.servlet.config.annotation.CorsRegistry; 3 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 4 5 /** 6 * @Author:CoderZZ 7 * @Description:Spring Boot全局支持CORS(跨源请求) 8 * @Date:Created in 10:57 2018/2/8. 9 */ 10 @Configuration 11 public class WebCorsConfigurerAdapter extends WebMvcConfigurerAdapter 12 { 13 14 @Override 15 public void addCorsMappings(CorsRegistry registry) { 16 registry.addMapping("/**"). 17 allowedOrigins("*"). 18 allowedMethods("GET", "HEAD", "POST","PUT", "DELETE", "OPTIONS"). 19 allowedHeaders("Content-Type","Access-Control-Allow-Headers","Authorization","X-Requested-With"). 20 allowCredentials(true); 21 } 22 }
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
· InnoDB为什么不用跳表,Redis为什么不用B+树?
· 记一次 C# 平台调用中因非托管 union 类型导致的内存访问越界
· [EF Core]聊聊“复合”属性
· 那些被推迟的 C# 14 特性及其背后的故事
· 我最喜欢的 C# 14 新特性
· 微软开源的 MCP 教程「GitHub 热点速览」
· 记一次 .NET 某汽车控制焊接软件 卡死分析
· 博客园出海记-开篇:扬帆启航
· InnoDB为什么不用跳表,Redis为什么不用B+树?
· 记一次C#平台调用中因非托管union类型导致的内存访问越界