1. @Bean
    2. public CorsFilter corsFilter() {
    3. final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    4. final CorsConfiguration corsConfiguration = new CorsConfiguration();
    5. corsConfiguration.setAllowCredentials(true);
    6. corsConfiguration.addAllowedOrigin("*");
    7. corsConfiguration.addAllowedHeader("*");
    8. corsConfiguration.addAllowedMethod("*");
    9. corsConfiguration.setMaxAge(10000L);
    10. //匹配所有API
    11. source.registerCorsConfiguration("/**", corsConfiguration);
    12. return new CorsFilter(source);
    13. }