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;
        }
    }
  • 相关阅读:
    敏捷开发感想
    团队分工
    My Partner‘s Code View
    课堂上面的练习
    APP测试用例
    Android App测试计划和设计测试矩阵
    BugReport-智慧农业APP
    图书管理系统的活动图和时序图
    图书管理系统用例图
    对图书管理系统5W1H的分析
  • 原文地址:https://www.cnblogs.com/rain-in-summer/p/13373234.html
Copyright © 2011-2022 走看看