springBoot项目后端配置跨域访问

@Configuration
    public class MyMvcConfig {

        @Bean
        public WebMvcConfigurer webMvcConfigurer() {
            return new WebMvcConfigurer() {

                //配置跨域
                @Override
                public void addCorsMappings(CorsRegistry registry) {
                    registry.addMapping("/**")     //允许的路径
                            .allowedMethods("*")     //允许的方法
                            .allowedOrigins("*")       //允许的网站
                            .allowedHeaders("*")     //允许的请求头
                            .allowCredentials(true)
                            .maxAge(3600);
                }
            };

        }

    }

只需要在启动类中加入此方法就可以实现跨域请求

上一篇:Failed to start an Appium session, err was: Error: Requested a new session but one was in progress


下一篇:vue 下载阿里云OSS远程图片,跨域问题, No 'Access-Control-Allow-Origin' header is present on the requested