-1

跨域请求被阻止:同源策略不允许在http://localhost:8080/index/home读取远程资源。(原因:缺少 CORS 标头“Access-Control-Allow-Origin”)。

客户端运行在 8000

rest 服务运行在 8080 并且服务有 @CrossOrigin(origins = " http://localhost:8000/ ")

但仍然无法正常工作

4

1 回答 1

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);
}   
于 2016-04-25T09:47:44.697 回答