惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
V
V2EX
G
Google Developers Blog
F
Full Disclosure
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
H
Hacker News: Front Page
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
NISL@THU
NISL@THU
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
About on SuperTechFans
The Cloudflare Blog
C
Cisco Blogs
D
DataBreaches.Net
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Vercel News
Vercel News
P
Privacy International News Feed
Microsoft Security Blog
Microsoft Security Blog
Help Net Security
Help Net Security
Recorded Future
Recorded Future
PCI Perspectives
PCI Perspectives
S
Schneier on Security
AI
AI
N
News | PayPal Newsroom
雷峰网
雷峰网
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
L
LINUX DO - 最新话题
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
Schneier on Security
Schneier on Security
S
Securelist
云风的 BLOG
云风的 BLOG
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
AWS News Blog
AWS News Blog
TaoSecurity Blog
TaoSecurity Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 三生石上(FineUI控件)
C
CXSECURITY Database RSS Feed - CXSecurity.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Cloudbric
Cloudbric
C
Cybersecurity and Infrastructure Security Agency CISA
Project Zero
Project Zero
C
Check Point Blog
S
Security Affairs

博客园 - 李小加

rapidocr_api 在windows下安装 MYSQL 创建用户 配置logging.properties解决浏览器访问tomcat日志文件出现中文乱码问题 linux 安装字体解决JAVA图形中文乱码问题 linux 系统上图形生成错误 java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment MySQL 按时间段统计SQL maven 本地库添加jar包 数据接口开发管理平台(starAPI) oracle 11g https://localhost:1158/em 无法访问 & 设置自增id 第三方开源小工具 静态代码检查 mysql 数据库集群连接配置 tomcat server.xml 配置优化 使用PowerDesigner16.5 逆向数据库生产表结构或导出word文档 SpringBoot、thymeleaf 国际化配置 在 centos7 系统中用 docker 创建 tomcat 服务镜像 JAVA 调用 com.google.protobuf mysql 删除多个字段重复的数据, 只保留最新的一条 Git linux服务端安装、windows 用户端使用
解决 SpringBoot 跨域请求问题
李小加 · 2021-09-24 · via 博客园 - 李小加
package com.xrh.demo;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

/**
 * 
 * 全局跨域配置
 * 
 */
@Configuration
public class GlobalCorsConfig {

    /**
     * 
     * 允许跨域调用的过滤器
     * 
     */
    @Bean
    public CorsFilter corsFilter() {

        CorsConfiguration config = new CorsConfiguration();

        //允许跨越发送cookie
        config.setAllowCredentials(true);
                
        //允许所有域名进行跨域调用
        List<String> list = new ArrayList<>();
        list.add("*");
        config.setAllowedOriginPatterns(list);

        //放行全部原始头信息
        config.addAllowedHeader("*");

        //允许所有请求方法跨域调用
        config.addAllowedMethod("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

        source.registerCorsConfiguration("/**", config);

        return new CorsFilter(source);

    }

}

李小家

posted @ 2021-09-24 09:37  李小加  阅读(83)  评论()    收藏  举报