前两天做项目用到iview,添加请求头后,后端做了跨域处理。在SpringBoot2.0没问题,换到SpringBoot 1.5.13后又出现跨域。。。下面是跨域处理代码:

@Configuration
public class CorsConfig extends WebMvcConfigurerAdapter {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").
                allowedOrigins("*").
                allowedMethods("DELETE","GET", "POST", "OPTIONS", "PUT")
                .allowedHeaders("Content-Type", "X-Requested-With", "accept", "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers")
                .exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials")
                .allowCredentials(true).maxAge(3600);
    }
}

改成如下代码后解决

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

感觉是vue把请求头封装,还增加了其他请求头内容,所以用枚举会出现跨域问题...

Logo

前往低代码交流专区

更多推荐