【单点登录】不清楚之前怎么处理跨域,先自己加上跨域
This commit is contained in:
parent
7d69521fa4
commit
e7b1b1cfd6
|
@ -1,7 +1,9 @@
|
|||
package io.renren.modules.monitor.config;
|
||||
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
@ -10,8 +12,8 @@ import org.springframework.web.filter.CorsFilter;
|
|||
public class GlobalCorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
//1. 添加 CORS配置信息
|
||||
public FilterRegistrationBean<CorsFilter> corsFilter() {
|
||||
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
//放行哪些原始域
|
||||
config.addAllowedOrigin("*");
|
||||
|
@ -23,10 +25,11 @@ public class GlobalCorsConfig {
|
|||
config.addAllowedHeader("*");
|
||||
//暴露哪些头部信息
|
||||
config.addExposedHeader("*");
|
||||
//2. 添加映射路径
|
||||
UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
||||
corsConfigurationSource.registerCorsConfiguration("/**",config);
|
||||
//3. 返回新的CorsFilter
|
||||
return new CorsFilter(corsConfigurationSource);
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
//项目中有多个filter时此处设置改CorsFilter的优先执行顺序
|
||||
FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
|
||||
bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue