本文主要是介绍renren开源里跨域出现access control Allow Origin的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
人人开源的文件中已经有了一个跨域
- 自己重新搞一个跨域要把这个删掉or注释
package io.renren.config;import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class CorsConfig implements WebMvcConfigurer {
//
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**")
// .allowedHeaders("access control Allow Origin")
// .allowedOrigins("http://localhost:8001")
// .allowCredentials(true)
// .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
// .maxAge(3600);
// }
}
重新搞一个跨域
package com.rod.bishe.bishegateway.config;import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;@Configuration
public class BisheCorsConfiguration {@Beanpublic CorsWebFilter corsWebFilter() {UrlBasedCorsConfigurationSource source =new UrlBasedCorsConfigurationSource();CorsConfiguration configuration = new CorsConfiguration();//配置跨域 Access-Control-Allow-Originconfiguration.addAllowedHeader("*");//这里要写具体的跨域的前端url不要写*configuration.addAllowedOrigin("http://localhost:8001");configuration.addAllowedMethod("*");configuration.setAllowCredentials(true);source.registerCorsConfiguration("/**", configuration);return new CorsWebFilter(source);}
}
这篇关于renren开源里跨域出现access control Allow Origin的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!