阻止跨源请求:同源策略禁止在http://localhost:8080/index/home读取远程资源。 (原因:缺少CORS标题'Access-Control-Allow-Origin'。
客户端以8000运行
休息服务在8080运行,服务有@CrossOrigin(originins =“http://localhost:8000/”)
但仍无法正常工作
答案 0 :(得分:0)
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("OPTIONS");
config.addAllowedMethod("HEAD");
config.addAllowedMethod("GET");
config.addAllowedMethod("PUT");
config.addAllowedMethod("POST");
config.addAllowedMethod("DELETE");
config.addAllowedMethod("PATCH");
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}