From 9bc1e4ac1e140e4bc68d33d3774489c029cc26a3 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期四, 15 六月 2023 14:13:18 +0800 Subject: [PATCH] update 重构 将系统内置配置放置到common包内独立加载 不允许用户随意修改 --- ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java | 31 ++++++++++ ruoyi-common/ruoyi-common-mybatis/src/main/resources/common-mybatis.yml | 33 +++++++++++ ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfig.java | 3 + ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/config/SaTokenConfig.java | 3 + ruoyi-common/ruoyi-common-satoken/src/main/resources/common-satoken.yml | 11 +++ ruoyi-admin/src/main/resources/application.yml | 41 +------------ 6 files changed, 85 insertions(+), 37 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index f599a84..b68a3dc 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -96,20 +96,14 @@ sa-token: # token鍚嶇О (鍚屾椂涔熸槸cookie鍚嶇О) token-name: Authorization - # token鏈夋晥鏈� 璁句负涓�澶� (蹇呭畾杩囨湡) 鍗曚綅: 绉� - timeout: 86400 - # token涓存椂鏈夋晥鏈� (鎸囧畾鏃堕棿鏃犳搷浣滃氨杩囨湡) 鍗曚綅: 绉� + # token鍥哄畾瓒呮椂 璁句负涓冨ぉ (蹇呭畾杩囨湡) 鍗曚綅: 绉� + timeout: 604800 + # token娲昏穬瓒呮椂鏃堕棿 30鍒嗛挓(鎸囧畾鏃堕棿鏃犳搷浣滃垯杩囨湡) 鍗曚綅: 绉� activity-timeout: 1800 # 鏄惁鍏佽鍚屼竴璐﹀彿骞跺彂鐧诲綍 (涓簍rue鏃跺厑璁镐竴璧风櫥褰�, 涓篺alse鏃舵柊鐧诲綍鎸ゆ帀鏃х櫥褰�) is-concurrent: true # 鍦ㄥ浜虹櫥褰曞悓涓�璐﹀彿鏃讹紝鏄惁鍏辩敤涓�涓猼oken (涓簍rue鏃舵墍鏈夌櫥褰曞叡鐢ㄤ竴涓猼oken, 涓篺alse鏃舵瘡娆$櫥褰曟柊寤轰竴涓猼oken) is-share: false - # 鏄惁灏濊瘯浠巋eader閲岃鍙杢oken - is-read-header: true - # 鏄惁灏濊瘯浠巆ookie閲岃鍙杢oken - is-read-cookie: false - # token鍓嶇紑 - token-prefix: "Bearer" # jwt绉橀挜 jwt-secret-key: abcdefghijklmnopqrstuvwxyz @@ -156,39 +150,12 @@ mapperLocations: classpath*:mapper/**/*Mapper.xml # 瀹炰綋鎵弿锛屽涓猵ackage鐢ㄩ�楀彿鎴栬�呭垎鍙峰垎闅� typeAliasesPackage: org.dromara.**.domain - # 鍚姩鏃舵槸鍚︽鏌� MyBatis XML 鏂囦欢鐨勫瓨鍦紝榛樿涓嶆鏌� - checkConfigLocation: false - configuration: - # 鑷姩椹煎嘲鍛藉悕瑙勫垯锛坈amel case锛夋槧灏� - mapUnderscoreToCamelCase: true - # MyBatis 鑷姩鏄犲皠绛栫暐 - # NONE锛氫笉鍚敤 PARTIAL锛氬彧瀵归潪宓屽 resultMap 鑷姩鏄犲皠 FULL锛氬鎵�鏈� resultMap 鑷姩鏄犲皠 - autoMappingBehavior: FULL - # MyBatis 鑷姩鏄犲皠鏃舵湭鐭ュ垪鎴栨湭鐭ュ睘鎬у鐞嗙瓥 - # NONE锛氫笉鍋氬鐞� WARNING锛氭墦鍗扮浉鍏宠鍛� FAILING锛氭姏鍑哄紓甯稿拰璇︾粏淇℃伅 - autoMappingUnknownColumnBehavior: NONE - # 鏇磋缁嗙殑鏃ュ織杈撳嚭 浼氭湁鎬ц兘鎹熻�� org.apache.ibatis.logging.stdout.StdOutImpl - # 鍏抽棴鏃ュ織璁板綍 (鍙崟绾娇鐢� p6spy 鍒嗘瀽) org.apache.ibatis.logging.nologging.NoLoggingImpl - # 榛樿鏃ュ織杈撳嚭 org.apache.ibatis.logging.slf4j.Slf4jImpl - logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl global-config: - # 鏄惁鎵撳嵃 Logo banner - banner: true dbConfig: # 涓婚敭绫诲瀷 # AUTO 鑷 NONE 绌� INPUT 鐢ㄦ埛杈撳叆 ASSIGN_ID 闆姳 ASSIGN_UUID 鍞竴 UUID + # 濡傞渶鏀逛负鑷 闇�瑕佸皢鏁版嵁搴撹〃鍏ㄩ儴璁剧疆涓鸿嚜澧� idType: ASSIGN_ID - # 閫昏緫宸插垹闄ゅ�� - logicDeleteValue: 2 - # 閫昏緫鏈垹闄ゅ�� - logicNotDeleteValue: 0 - # 瀛楁楠岃瘉绛栫暐涔� insert,鍦� insert 鐨勬椂鍊欑殑瀛楁楠岃瘉绛栫暐 - # IGNORED 蹇界暐 NOT_NULL 闈濶ULL NOT_EMPTY 闈炵┖ DEFAULT 榛樿 NEVER 涓嶅姞鍏� SQL - insertStrategy: NOT_NULL - # 瀛楁楠岃瘉绛栫暐涔� update,鍦� update 鐨勬椂鍊欑殑瀛楁楠岃瘉绛栫暐 - updateStrategy: NOT_NULL - # 瀛楁楠岃瘉绛栫暐涔� select,鍦� select 鐨勬椂鍊欑殑瀛楁楠岃瘉绛栫暐鏃� wrapper 鏍规嵁鍐呴儴 entity 鐢熸垚鐨� where 鏉′欢 - where-strategy: NOT_NULL # 鏁版嵁鍔犲瘑 mybatis-encryptor: diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java new file mode 100644 index 0000000..af61b90 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/factory/YmlPropertySourceFactory.java @@ -0,0 +1,31 @@ +package org.dromara.common.core.factory; + +import org.dromara.common.core.utils.StringUtils; +import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; +import org.springframework.core.env.PropertiesPropertySource; +import org.springframework.core.env.PropertySource; +import org.springframework.core.io.support.DefaultPropertySourceFactory; +import org.springframework.core.io.support.EncodedResource; + +import java.io.IOException; + +/** + * yml 閰嶇疆婧愬伐鍘� + * + * @author Lion Li + */ +public class YmlPropertySourceFactory extends DefaultPropertySourceFactory { + + @Override + public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException { + String sourceName = resource.getResource().getFilename(); + if (StringUtils.isNotBlank(sourceName) && StringUtils.endsWithAny(sourceName, ".yml", ".yaml")) { + YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean(); + factory.setResources(resource.getResource()); + factory.afterPropertiesSet(); + return new PropertiesPropertySource(sourceName, factory.getObject()); + } + return super.createPropertySource(name, resource); + } + +} diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfig.java b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfig.java index 1fe7834..c07a2bb 100644 --- a/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfig.java +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/config/MybatisPlusConfig.java @@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import org.dromara.common.core.factory.YmlPropertySourceFactory; import org.dromara.common.mybatis.handler.InjectionMetaObjectHandler; import org.dromara.common.mybatis.interceptor.PlusDataPermissionInterceptor; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.PropertySource; import org.springframework.transaction.annotation.EnableTransactionManagement; /** @@ -22,6 +24,7 @@ @EnableTransactionManagement(proxyTargetClass = true) @AutoConfiguration @MapperScan("${mybatis-plus.mapperPackage}") +@PropertySource(value = "classpath:common-mybatis.yml", factory = YmlPropertySourceFactory.class) public class MybatisPlusConfig { @Bean diff --git a/ruoyi-common/ruoyi-common-mybatis/src/main/resources/common-mybatis.yml b/ruoyi-common/ruoyi-common-mybatis/src/main/resources/common-mybatis.yml new file mode 100644 index 0000000..f5dc637 --- /dev/null +++ b/ruoyi-common/ruoyi-common-mybatis/src/main/resources/common-mybatis.yml @@ -0,0 +1,33 @@ +# 鍐呯疆閰嶇疆 涓嶅厑璁镐慨鏀� 濡傞渶淇敼璇峰湪 nacos 涓婂啓鐩稿悓閰嶇疆瑕嗙洊 +# MyBatisPlus閰嶇疆 +# https://baomidou.com/config/ +mybatis-plus: + # 鍚姩鏃舵槸鍚︽鏌� MyBatis XML 鏂囦欢鐨勫瓨鍦紝榛樿涓嶆鏌� + checkConfigLocation: false + configuration: + # 鑷姩椹煎嘲鍛藉悕瑙勫垯锛坈amel case锛夋槧灏� + mapUnderscoreToCamelCase: true + # MyBatis 鑷姩鏄犲皠绛栫暐 + # NONE锛氫笉鍚敤 PARTIAL锛氬彧瀵归潪宓屽 resultMap 鑷姩鏄犲皠 FULL锛氬鎵�鏈� resultMap 鑷姩鏄犲皠 + autoMappingBehavior: FULL + # MyBatis 鑷姩鏄犲皠鏃舵湭鐭ュ垪鎴栨湭鐭ュ睘鎬у鐞嗙瓥 + # NONE锛氫笉鍋氬鐞� WARNING锛氭墦鍗扮浉鍏宠鍛� FAILING锛氭姏鍑哄紓甯稿拰璇︾粏淇℃伅 + autoMappingUnknownColumnBehavior: NONE + # 鏇磋缁嗙殑鏃ュ織杈撳嚭 浼氭湁鎬ц兘鎹熻�� org.apache.ibatis.logging.stdout.StdOutImpl + # 鍏抽棴鏃ュ織璁板綍 (鍙崟绾娇鐢� p6spy 鍒嗘瀽) org.apache.ibatis.logging.nologging.NoLoggingImpl + # 榛樿鏃ュ織杈撳嚭 org.apache.ibatis.logging.slf4j.Slf4jImpl + logImpl: org.apache.ibatis.logging.nologging.NoLoggingImpl + global-config: + # 鏄惁鎵撳嵃 Logo banner + banner: true + dbConfig: + # 涓婚敭绫诲瀷 + # AUTO 鑷 NONE 绌� INPUT 鐢ㄦ埛杈撳叆 ASSIGN_ID 闆姳 ASSIGN_UUID 鍞竴 UUID + idType: ASSIGN_ID + # 閫昏緫宸插垹闄ゅ��(妗嗘灦琛ㄥ潎浣跨敤姝ゅ�� 绂佹闅忔剰淇敼) + logicDeleteValue: 2 + # 閫昏緫鏈垹闄ゅ�� + logicNotDeleteValue: 0 + insertStrategy: NOT_NULL + updateStrategy: NOT_NULL + whereStrategy: NOT_NULL diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/config/SaTokenConfig.java b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/config/SaTokenConfig.java index 54ae2da..aef8a66 100644 --- a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/config/SaTokenConfig.java +++ b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/config/SaTokenConfig.java @@ -4,10 +4,12 @@ import cn.dev33.satoken.jwt.StpLogicJwtForSimple; import cn.dev33.satoken.stp.StpInterface; import cn.dev33.satoken.stp.StpLogic; +import org.dromara.common.core.factory.YmlPropertySourceFactory; import org.dromara.common.satoken.core.dao.PlusSaTokenDao; import org.dromara.common.satoken.core.service.SaPermissionImpl; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.PropertySource; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** @@ -16,6 +18,7 @@ * @author Lion Li */ @AutoConfiguration +@PropertySource(value = "classpath:common-satoken.yml", factory = YmlPropertySourceFactory.class) public class SaTokenConfig implements WebMvcConfigurer { @Bean diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/resources/common-satoken.yml b/ruoyi-common/ruoyi-common-satoken/src/main/resources/common-satoken.yml new file mode 100644 index 0000000..c631641 --- /dev/null +++ b/ruoyi-common/ruoyi-common-satoken/src/main/resources/common-satoken.yml @@ -0,0 +1,11 @@ +# 鍐呯疆閰嶇疆 涓嶅厑璁镐慨鏀� 濡傞渶淇敼璇峰湪 nacos 涓婂啓鐩稿悓閰嶇疆瑕嗙洊 +# Sa-Token閰嶇疆 +sa-token: + # 鍏佽浠� 璇锋眰鍙傛暟 璇诲彇 token + is-read-body: true + # 鍏佽浠� header 璇诲彇 token + is-read-header: true + # 鍏抽棴 cookie 閴存潈 浠庢牴婧愭潨缁� csrf 婕忔礊椋庨櫓 + is-read-cookie: false + # token鍓嶇紑 + token-prefix: "Bearer" -- Gitblit v1.9.3