From edb9a176966691a60bf75cbbdd4b24eb9d91b361 Mon Sep 17 00:00:00 2001 From: chenpeng0206 Date: Thu, 4 Aug 2022 10:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=A8=E5=9F=9F=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 告警细节.txt | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/告警细节.txt b/告警细节.txt index 31eccbc..45f86bf 100644 --- a/告警细节.txt +++ b/告警细节.txt @@ -98,4 +98,33 @@ "alarmTime": "2022-05-10T05:06:22", "alarmEvent": "ws服务异常" } - */ \ No newline at end of file + */ + + + /** + * 跨域配置 + */ + @Bean + public CorsFilter corsFilter() + { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + // 是否允许请求带有验证信息 + config.setAllowCredentials(true); + + // 允许访问的客户端域名 + // (springboot2.4以上的加入这一段可解决 allowedOrigins cannot contain the special value "*"问题) + List allowedOriginPatterns = new ArrayList<>(); + allowedOriginPatterns.add("*"); + config.setAllowedOriginPatterns(allowedOriginPatterns); + + // 设置访问源地址 + // config.addAllowedOrigin("*"); + // 设置访问源请求头 + config.addAllowedHeader("*"); + // 设置访问源请求方法 + config.addAllowedMethod("*"); + // 对接口配置跨域设置 + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } \ No newline at end of file