zoukankan      html  css  js  c++  java
  • SpringBoot 处理跨域请求问题

    增加一个配置类

    package com.config;
    
    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 CorsConfig {
    
        @Bean
        public CorsFilter corsFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            source.registerCorsConfiguration("/**", corsConfig());
            return new CorsFilter(source);
        }
    
        private CorsConfiguration corsConfig() {
            CorsConfiguration corsConfiguration = new CorsConfiguration();
            corsConfiguration.addAllowedOrigin("*");
            corsConfiguration.addAllowedHeader("*");
            corsConfiguration.addAllowedMethod("*");
            corsConfiguration.setAllowCredentials(true);
            corsConfiguration.setMaxAge(3600L);
            return corsConfiguration;
        }
    }
  • 相关阅读:
    Wamp 扩展Oracle Oci
    Yii 网站上线不需手动配置
    Centos 设置时区
    Crontab 入门
    centos apache安装oracle扩展
    Centos rpm 卸载
    mac vagrant 虚拟机nfs挂载点
    搭建php虚拟环境
    Mac 安装package control
    Sublime 安装、删除插件
  • 原文地址:https://www.cnblogs.com/pxblog/p/13035281.html
Copyright © 2011-2022 走看看