mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 重构 将系统内置配置放置到common包内独立加载 不允许用户随意修改
This commit is contained in:
		@@ -96,20 +96,14 @@ spring:
 | 
			
		||||
sa-token:
 | 
			
		||||
  # token名称 (同时也是cookie名称)
 | 
			
		||||
  token-name: Authorization
 | 
			
		||||
  # token有效期 设为一天 (必定过期) 单位: 秒
 | 
			
		||||
  timeout: 86400
 | 
			
		||||
  # token临时有效期 (指定时间无操作就过期) 单位: 秒
 | 
			
		||||
  # token固定超时 设为七天 (必定过期) 单位: 秒
 | 
			
		||||
  timeout: 604800
 | 
			
		||||
  # token活跃超时时间 30分钟(指定时间无操作则过期) 单位: 秒
 | 
			
		||||
  activity-timeout: 1800
 | 
			
		||||
  # 是否允许同一账号并发登录 (为true时允许一起登录, 为false时新登录挤掉旧登录)
 | 
			
		||||
  is-concurrent: true
 | 
			
		||||
  # 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
 | 
			
		||||
  is-share: false
 | 
			
		||||
  # 是否尝试从header里读取token
 | 
			
		||||
  is-read-header: true
 | 
			
		||||
  # 是否尝试从cookie里读取token
 | 
			
		||||
  is-read-cookie: false
 | 
			
		||||
  # token前缀
 | 
			
		||||
  token-prefix: "Bearer"
 | 
			
		||||
  # jwt秘钥
 | 
			
		||||
  jwt-secret-key: abcdefghijklmnopqrstuvwxyz
 | 
			
		||||
 | 
			
		||||
@@ -156,39 +150,12 @@ mybatis-plus:
 | 
			
		||||
  mapperLocations: classpath*:mapper/**/*Mapper.xml
 | 
			
		||||
  # 实体扫描,多个package用逗号或者分号分隔
 | 
			
		||||
  typeAliasesPackage: org.dromara.**.domain
 | 
			
		||||
  # 启动时是否检查 MyBatis XML 文件的存在,默认不检查
 | 
			
		||||
  checkConfigLocation: false
 | 
			
		||||
  configuration:
 | 
			
		||||
    # 自动驼峰命名规则(camel 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 非NULL NOT_EMPTY 非空 DEFAULT 默认 NEVER 不加入 SQL
 | 
			
		||||
      insertStrategy: NOT_NULL
 | 
			
		||||
      # 字段验证策略之 update,在 update 的时候的字段验证策略
 | 
			
		||||
      updateStrategy: NOT_NULL
 | 
			
		||||
      # 字段验证策略之 select,在 select 的时候的字段验证策略既 wrapper 根据内部 entity 生成的 where 条件
 | 
			
		||||
      where-strategy: NOT_NULL
 | 
			
		||||
 | 
			
		||||
# 数据加密
 | 
			
		||||
mybatis-encryptor:
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -7,11 +7,13 @@ import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
 | 
			
		||||
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 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 | 
			
		||||
@EnableTransactionManagement(proxyTargetClass = true)
 | 
			
		||||
@AutoConfiguration
 | 
			
		||||
@MapperScan("${mybatis-plus.mapperPackage}")
 | 
			
		||||
@PropertySource(value = "classpath:common-mybatis.yml", factory = YmlPropertySourceFactory.class)
 | 
			
		||||
public class MybatisPlusConfig {
 | 
			
		||||
 | 
			
		||||
    @Bean
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
# 内置配置 不允许修改 如需修改请在 nacos 上写相同配置覆盖
 | 
			
		||||
# MyBatisPlus配置
 | 
			
		||||
# https://baomidou.com/config/
 | 
			
		||||
mybatis-plus:
 | 
			
		||||
  # 启动时是否检查 MyBatis XML 文件的存在,默认不检查
 | 
			
		||||
  checkConfigLocation: false
 | 
			
		||||
  configuration:
 | 
			
		||||
    # 自动驼峰命名规则(camel 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
 | 
			
		||||
@@ -4,10 +4,12 @@ import cn.dev33.satoken.dao.SaTokenDao;
 | 
			
		||||
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 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 | 
			
		||||
 * @author Lion Li
 | 
			
		||||
 */
 | 
			
		||||
@AutoConfiguration
 | 
			
		||||
@PropertySource(value = "classpath:common-satoken.yml", factory = YmlPropertySourceFactory.class)
 | 
			
		||||
public class SaTokenConfig implements WebMvcConfigurer {
 | 
			
		||||
 | 
			
		||||
    @Bean
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
		Reference in New Issue
	
	Block a user