0
点赞
收藏
分享

微信扫一扫

【力扣】【好题】560.和为k的子数组 || 前缀和

爱写作的小土豆 2024-03-29 阅读 8
java

统一跨域解决方案之一

package com.xie.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 {
    /**
     * 当前跨域请求最大有效时长;
     * 这里默认为1天
     * */
    private static final long MAX_AGE = 24 * 60 * 60;
    @Bean
    public CorsFilter corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
        corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头
        corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法
        corsConfiguration.setMaxAge(MAX_AGE);
        source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置
        return new CorsFilter(source);
    }
}
举报

相关推荐

0 条评论