From 210b5af1c7f15f45c5d1abca607bd8d942a2b66a Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期一, 02 八月 2021 09:39:35 +0800 Subject: [PATCH] update 优化自动注入器 异常检查更完善 --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java | 32 ++++++++++++++++++++++++++------ 1 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java index f10ea2d..c3cdc94 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/ResourcesConfig.java @@ -1,7 +1,11 @@ package com.ruoyi.framework.config; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +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.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -11,7 +15,7 @@ /** * 閫氱敤閰嶇疆 - * + * * @author ruoyi */ @Configuration @@ -25,10 +29,6 @@ { /** 鏈湴鏂囦欢涓婁紶璺緞 */ registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**").addResourceLocations("file:" + RuoYiConfig.getProfile() + "/"); - - /** swagger閰嶇疆 */ - registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); - registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); } /** @@ -39,4 +39,24 @@ { registry.addInterceptor(repeatSubmitInterceptor).addPathPatterns("/**"); } -} \ No newline at end of file + + /** + * 璺ㄥ煙閰嶇疆 + */ + @Bean + public CorsFilter corsFilter() + { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + // 璁剧疆璁块棶婧愬湴鍧� + config.addAllowedOriginPattern("*"); + // 璁剧疆璁块棶婧愯姹傚ご + config.addAllowedHeader("*"); + // 璁剧疆璁块棶婧愯姹傛柟娉� + config.addAllowedMethod("*"); + // 瀵规帴鍙i厤缃法鍩熻缃� + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } +} -- Gitblit v1.9.3