0
点赞
收藏
分享

微信扫一扫

第五章 SpringBoot快速开发框架 - 跨域配置

四月Ren间 2022-05-01 阅读 101


五、跨域配置

跨域配置

package com.lll.framework.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig {
    @Bean
    public WebMvcConfigurer corsConfigurer(){
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**")
                        .allowCredentials(true)
                        .allowedHeaders("*")
                        .allowedMethods("*")
                        .allowedOrigins("*")
                        .maxAge(3600);
            }
        };
    }
}


举报

相关推荐

0 条评论