springboot 项目,前后端分离项目,允许的跨域访问地址的配置

2021-09-26 11:02:09 浏览数 (2)

目录

代码语言:javascript复制
@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "DELETE", "PUT","OPTIONS")
                .maxAge(3600);
        super.addCorsMappings(registry);
    }
}

0 人点赞