From 0bf868d3cdf9226e178c076d3b588ed5207409a0 Mon Sep 17 00:00:00 2001 From: kongzy <kongzy> Date: 星期五, 24 十一月 2023 17:51:40 +0800 Subject: [PATCH] merge --- assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) diff --git a/assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java b/assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java new file mode 100644 index 0000000..88c51df --- /dev/null +++ b/assess-framework/src/main/java/com/gkhy/assess/framework/config/ApplicationConfig.java @@ -0,0 +1,51 @@ +package com.gkhy.assess.framework.config; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +import java.util.TimeZone; + +/** + * 程序注解配置 + * + * @author ruoyi + */ +@Configuration +// 表示通过aop框架暴露该代理对象,AopContext能够访问 +@EnableAspectJAutoProxy(exposeProxy = true) +// 指定要扫描的Mapper类的包的路径 +@MapperScan("com.gkhy.**.mapper") +public class ApplicationConfig +{ + /** + * 时区配置 + */ + @Bean + public Jackson2ObjectMapperBuilderCustomizer jacksonObjectMapperCustomization() + { + return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.timeZone(TimeZone.getDefault()); + } + + @Bean + public CorsFilter corsFilter() { + final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource(); + final CorsConfiguration corsConfiguration = new CorsConfiguration(); + //是否允许请求带有验证信息 + corsConfiguration.setAllowCredentials(true); + // 允许访问的客户端域名 + corsConfiguration.addAllowedOriginPattern("*"); + // 允许服务端访问的客户端请求头 + corsConfiguration.addAllowedHeader("*"); + // 允许访问的方法名,GET POST等 + corsConfiguration.addAllowedMethod("*"); + urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration); + return new CorsFilter(urlBasedCorsConfigurationSource); + } +} -- Gitblit v1.9.2