content: package com.intelligent.bot.config;
  
  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;
  
  
  @Configuration
  public class CorsConfig   {
  
  
      @Bean
      public FilterRegistrationBean<CorsFilter> corsFilter() {
          CorsConfiguration corsConfig = new CorsConfiguration();
          corsConfig.setAllowCredentials(true);
          corsConfig.addAllowedOrigin(CorsConfiguration.ALL);
          corsConfig.addAllowedMethod(CorsConfiguration.ALL);
          corsConfig.addAllowedHeader(CorsConfiguration.ALL);
          //默认可不设置这个暴露的头。这个为了安全问题，不能使用*。设置成*，后面会报错：throw new IllegalArgumentException("'*' is not a valid exposed header value");
          //corsConfig.addExposedHeader("");
          corsConfig.setMaxAge(3600L);
  
          UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
          configSource.registerCorsConfiguration("/**", corsConfig);
  
          FilterRegistrationBean<CorsFilter> corsBean = new FilterRegistrationBean<CorsFilter>(new CorsFilter(configSource));
          corsBean.setName("crossOriginFilter");
          corsBean.setOrder(0);//这个顺序也有可能会有影响，尽量设置在拦截器前面
          return corsBean;
      }
  
  }