全局过滤器
# 全局过滤器
## 同意所有的预检请求
```java
@Configuration
public class CorsConfig {
/**
* 跨域过滤器
* @return
*/
@Bean
public CorsWebFilter corsWebFilter() {
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedHeader("*"); // 允许所有的请求头
corsConfiguration.addAllowedMethod("*"); // 允许所有的请求方式
corsConfiguration.addAllowedOrigin("*"); // 允许所有的来源
corsConfiguration.setAllowCredentials(true);
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); // 允许所有的path
return new CorsWebFilter(urlBasedCorsConfigurationSource);
}
}
```