From 765d9a3de208ba1ea9a10f9b1bd6fba08afd2079 Mon Sep 17 00:00:00 2001 From: 林致杰 <1003392067@qq.com> Date: 星期四, 26 十月 2023 16:02:44 +0800 Subject: [PATCH] 新增LAQ图表替换 --- src/main/java/com/ots/framework/config/ResourcesConfig.java | 43 ++++++++++++++++++++++++++++++++++--------- 1 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ots/framework/config/ResourcesConfig.java b/src/main/java/com/ots/framework/config/ResourcesConfig.java index e9d2106..5822c7b 100644 --- a/src/main/java/com/ots/framework/config/ResourcesConfig.java +++ b/src/main/java/com/ots/framework/config/ResourcesConfig.java @@ -1,36 +1,61 @@ package com.ots.framework.config; + import com.ots.framework.interceptor.RepeatSubmitInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.config.annotation.*; @Configuration public class ResourcesConfig implements WebMvcConfigurer { - + @Value("${shiro.user.indexUrl}") private String indexUrl; @Autowired private RepeatSubmitInterceptor repeatSubmitInterceptor; - + @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("forward:" + indexUrl); } + @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - + registry.addResourceHandler("/profile/**").addResourceLocations("file:" + EssConfig.getProfile() + "/"); - + registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } - + @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**"); } + + /** + * 璺ㄥ煙閰嶇疆 + */ + @Bean + public CorsFilter corsFilter() { + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + // 璁剧疆璁块棶婧愬湴鍧� + config.addAllowedOrigin("*"); + // 璁剧疆璁块棶婧愯姹傚ご + config.addAllowedHeader("*"); + // 璁剧疆璁块棶婧愯姹傛柟娉� + config.addAllowedMethod("*"); + // 鏈夋晥鏈� 1800绉� + config.setMaxAge(1800L); + // 娣诲姞鏄犲皠璺緞锛屾嫤鎴竴鍒囪姹� + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + // 杩斿洖鏂扮殑CorsFilter + return new CorsFilter(source); + } } -- Gitblit v1.9.1