解决方案:12345678910111213141516171819/** * 设置跨域请求 */@Configurationpublic class MyConfiguration { @Bean public FilterRegistrationBean corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); config.addAllowedOrigin("*");// 1 设置访问源地址 config.addAllowedHeader("*");// 2 设置访问源请求头 config.addAllowedMethod("*");// 3 设置访问源请求方法 source.registerCorsConfiguration("/**", config); FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); bean.setOrder(0); return bean; }}