From 1feb2e2a39101eaa2bec391b91c97f92d75fbda7 Mon Sep 17 00:00:00 2001 From: Lovsog <59257085+Art0white@users.noreply.github.com> Date: Mon, 31 Oct 2022 17:55:20 +0800 Subject: [PATCH] Update WebConfigurer.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit config.addAllowedOrigin("*");方法实现不了跨域,需改为config.addAllowedOriginPattern("*"); --- .../src/main/java/com/example/demo/config/WebConfigurer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/48.Spring-Boot-CORS-Support/src/main/java/com/example/demo/config/WebConfigurer.java b/48.Spring-Boot-CORS-Support/src/main/java/com/example/demo/config/WebConfigurer.java index e85b522a..1e1d3085 100644 --- a/48.Spring-Boot-CORS-Support/src/main/java/com/example/demo/config/WebConfigurer.java +++ b/48.Spring-Boot-CORS-Support/src/main/java/com/example/demo/config/WebConfigurer.java @@ -27,7 +27,7 @@ public FilterRegistrationBean corsFilter() { UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration config = new CorsConfiguration(); config.setAllowCredentials(true); - config.addAllowedOrigin("*"); + config.addAllowedOriginPattern("*"); source.registerCorsConfiguration("/**", config); FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source)); bean.setOrder(0);