|
|
|
@ -4,6 +4,10 @@ import cn.chjyj.szwh.xss.XssFilter; |
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean; |
|
|
|
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; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.DispatcherType; |
|
|
|
|
|
|
|
@ -23,4 +27,27 @@ public class FilterConfig { |
|
|
|
registration.setOrder(Integer.MAX_VALUE); |
|
|
|
return registration; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 跨域访问控制 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Bean |
|
|
|
public CorsFilter corsFilter(){ |
|
|
|
CorsConfiguration config = new CorsConfiguration(); |
|
|
|
config.addAllowedOrigin("*"); |
|
|
|
config.setAllowCredentials(true); |
|
|
|
// 开放的请求方式
|
|
|
|
config.addAllowedMethod("GET"); |
|
|
|
config.addAllowedMethod("POST"); |
|
|
|
config.addAllowedHeader("*"); |
|
|
|
//暴露头部信息
|
|
|
|
config.addExposedHeader("*"); |
|
|
|
|
|
|
|
//添加映射路径
|
|
|
|
UrlBasedCorsConfigurationSource configsoure =new UrlBasedCorsConfigurationSource(); |
|
|
|
configsoure.registerCorsConfiguration("/**",config); |
|
|
|
|
|
|
|
return new CorsFilter(configsoure); |
|
|
|
} |
|
|
|
} |
|
|
|
|