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;
        }
    }
  • 相关阅读:
    for else
    改变注释字体颜色
    多继承
    模块的查找顺序
    如何跳出多层嵌套
    验证码书写
    正则表达式(一)
    四、列表与超链接
    三、表格与表单
    二、HTML入门
  • 原文地址:https://www.cnblogs.com/rain-in-summer/p/13373234.html
Copyright © 2011-2022 走看看