zoukankan      html  css  js  c++  java
  • springboot处理跨域

    
    
    package com.summer.config;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
    import org.springframework.web.filter.CorsFilter;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    
    /**
     * class:CorsConfiguration
     * description:
     *
     */
    @Configuration
    public class CorsConfiguration implements WebMvcConfigurer {
    
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            registry.addMapping("/**").allowedHeaders("*").allowedMethods("*").allowedOrigins("*");
        }
    
        @Bean
        public CorsFilter corsFilter() {
            UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
            source.registerCorsConfiguration("/**", buildConfig()); // 4 对接口配置跨域设置
            return new CorsFilter(source);
        }
    
        private org.springframework.web.cors.CorsConfiguration buildConfig() {
            org.springframework.web.cors.CorsConfiguration corsConfiguration = new org.springframework.web.cors.CorsConfiguration();
            corsConfiguration.addAllowedOrigin("*");
            corsConfiguration.addAllowedHeader("*");
            corsConfiguration.addAllowedMethod("*");
            return corsConfiguration;
        }
    }
  • 相关阅读:
    c# DataTable 转为 List 类型
    .net配置文件读取
    文件重命名(递归)
    sharepoint 网站创建
    Sharepoint添加顶部导航菜单
    .net sharepoint文档库操作
    c#下载共享文件夹下的文件并记录错误日志
    JS命名空间实例
    js时间处理函数
    模块
  • 原文地址:https://www.cnblogs.com/rain-in-summer/p/13373234.html
Copyright © 2011-2022 走看看