SpringCloud 跨域访问cors

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter; @Configuration
public class CorsConfiguraction {
/**
* 配置跨域请求
* @return
*/
@Bean
public CorsFilter corsFilter() {
//初始化cors配置对象
CorsConfiguration corsConfiguraction = new CorsConfiguration();
//允许跨域的域名
corsConfiguraction.addAllowedOrigin("http://xxx.xxx.com");
//允许cookie
corsConfiguraction.setAllowCredentials(true);
//可跨域的请求方式 如get put,post....
corsConfiguraction.addAllowedMethod("*");
//允许携带任何头信息
corsConfiguraction.addAllowedHeader("*");
//初始化cors配置源对象
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguraction);
return new CorsFilter(urlBasedCorsConfigurationSource);
} }
上一篇:[poj 2991]Crane[线段树表示向量之和,而非数量]


下一篇:ST&倍增LCA