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;
        }
    }
  • 相关阅读:
    对称加密和非对称加密
    SpringMVC 请求调用过程
    Swagger2常用注解和使用方法
    玩转汉诺塔
    java序列化
    判断当前时间是否在某时间段内
    docker限制容器日志大小
    MySQL数据库备份与恢复
    MySQL事物
    MySQL用户
  • 原文地址:https://www.cnblogs.com/pxblog/p/13035281.html
Copyright © 2011-2022 走看看