Skip to content

YML 配置文件

文件位置

yml 文件用途

  1. application.yml: 全局配置文件
  2. application-dev.yml: 开发时使用的配置文件
  3. application-test.yml: 测试时使用的配置文件
  4. application-xxx.yml: xxx生产时使用的配置文件

application.yml: 全局配置文件

spring

yaml
spring:
  #环境 dev|internet|government|jinhong|house
  profiles:
    active: dev
  1. spring.profiles.active=*
    *正好匹配 application-*.yml 配置文件,app 启动时,项目会先从 application-*.yml 加载配置。

application-*.yml: 各种场景下的配置文件

spring-boot 整合 jasypt 加密 yml 配置文件

通常项目配置文件中的账号信息如下,都是直接暴露出来的,如果源码不小心泄露将会引起一系列安全问题

yaml
jasypt:
  encryptor:
    password: ztgis #加解密秘钥
    algorithm: PBEWithMD5AndDES #默认算法
    iv-generator-classname: org.jasypt.iv.NoIvGenerator

步骤:

同ztgis-boot

数据源配置

  • 密码都需要jasypt加密
  • druid 默认关闭(enabled:false)
yaml
spring:
  # 数据源
  datasource:
    url: jdbc:oracle:thin:@xxx/xxx
    username: xxx
    password: ENC(xxx)
    type: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.OracleDriver
    logSlowSql: false #true
    # Druid StatViewServlet配置
    druid:
      stat-view-servlet:
        # 默认true 内置监控页面首页/druid/index.html
        enabled: false
        url-pattern: /druid/*
        # 允许清空统计数据
        reset-enable: false
        login-username: xxx
        login-password: ENC(xxx)
        # IP白名单 多个逗号分隔
        allow:
        # IP黑名单
        deny:
      filter:
        stat:
          # 显示慢sql 默认当超过3秒显示
          log-slow-sql: false #true
  jpa:
    database: oracle
    # 显示sql
    show-sql: false #true
    # 自动生成表结构
    generate-ddl: false #true
    open-in-view: false
    # hibernate:
    # ddl-auto: update

Redis 配置

  • 密码需要jasypt加密
  • 生产环境勿使用默认6379端口
yaml
spring:
  # Redis配置
  redis:
    host: 127.0.0.1 #192.168.100.110
    password: ENC(xxx)
    # 数据库索引 默认0
    database: 4
    integratedQueryDb: 1
    port: 6380  # 不要使用默认端口
    # 超时时间 Duration类型 3秒
    timeout: 3S
    maxActive: 100
    maxIdle: 100
    minIdle: 8
    maxWait: 3000
    testOnBorrow: true
    testOnReturn: true
    testWhileIdle: true

禁止上传文件类型

yml
gis-boot:
# 禁止上传的附件类型
  file-forbidden:
    formats:
      - .asp
      - .php
      - .aspx
      - .jsp
      - .asmx

密码策略配置

密码安全规范

yaml
gis-boot:
  password-strategy:
    # 是否启用
    enable: true
    # 过期时间(天)
    expireTime: 90
    # 是否允许与上一次一致
    sameWithLast: false

登录失败账户锁定配置

yaml
gis-boot:
  # token交互方式
  token:
    # 设置为true后,token将存入redis,并具有单点登录功能 默认false使用JWT交互
    redis: true
    # 是否开启单设备登陆 仅当token交互方式为redis时生效
    sdl: true
    # token中存储用户权限数据 设为true开启后可避免每次请求再获取用户权限,但有可能导致编辑权限菜单后无法读取到最新权限数据(需用户重新登录)
    storePerms: true
    # token过期时间(分钟)
    tokenExpireTime: 60
    # 用户选择保存登录状态对应token过期时间(天)
    saveLoginTime: 7
    # 限制用户登陆错误次数(次)
    loginTimeLimit: 5
    # 错误超过次数后多少分钟后才能继续登录(分钟)
    loginAfterTime: 10

自定义安全设置

  • sm4 配置
  • 是否登录
  • 是否权限校验
  • 是否黑名单
  • 是否验证码
yml
# 自定义安全机制 可省略系统表
custom-security:
  login: true #是否有登录 对应
  permission: true #是否有权限
  black-ip: true #是否校验黑名单ip
  verify-code: false # 是否登录需要校验验证码
  sm4-key: C7A5F1C7EDA4A7FA # key
  sm4-iv: E97C2E8B6B9566ED #iv

Jar 授权日期配置

DesUtils 加密,加密前格式YYYY—MM-DD

yaml
gis-boot:
  expiration: c7Pbp+uHF+2Qzm/RXG9eCg==

忽略鉴权配置

  • swagger / druid 的地址正式环境需要注释
  • 业务接口按实际情况开启
yaml
# 忽略鉴权url
ignored:
  urls:
    - /gisBoot/**
    - /gisBoot/app/v1/**
    - /gisBoot/oauth2/**
    - /gisBoot/actuator/**
    - /gisBoot/admin/**
    - /gisBoot/act/**
    - /gisBoot/dictData/getByType/**
    - /gisBoot/email/sendResetCode/**
    - /gisBoot/email/resetByEmail
    - /gisBoot/file/view/**
    - /gisBoot/social/**
    - /gisBoot/ws/**
    - /gisBoot/setting/notice
    - /gisBoot/user/regist
    - /gisBoot/user/smsLogin
    - /gisBoot/user/resetByMobile
    - /gisBoot/common/**
    - /gisBoot/generator/server/**
    - /gisBoot/generator/vue/**
    - /editor-app/**
#    - /druid/**
#    - /swagger-ui.html
#    - /swagger-resources/**
#    - /swagger/**
    - /doc.html
    - /**/v2/api-docs
    - /**/*.js
    - /**/*.css
    - /**/*.png
    - /**/*.ico
    - /**/*.txt
    - 部分业务接口

跨域配置

yaml
allow-origin:
  urls:
    - "*"
    - "http://127.0.0.1"
    - "http://a.b.c"
    - "xxxxxx"

微信Wechat配置

yml
wx:
  mp:
    appId: 微信appid
    secret: 微信密钥
    token:
    aesKey:

Actuator

  • 正式环境关闭
  • 使用非接口端口
  • 关闭忽略鉴权路径
yml
# Actuator
management:
  health:
    # 暂未用到ES 关闭其健康检查
    elasticsearch:
      enabled: false
  endpoint:
    health:
      show-details: always
      status:
        http-mapping:
          DOWN: 200
          OUT_OF_SERVICE: 200
          FATAL: 200
          UNKNOWN: 200
    #    enabled: false # 禁用部分接口,如env:x
    env:
      enabled: false
  endpoints:
    web:
      base-path: /gisBoot/actuator/
      exposure:
        include: '*'
        # 不允许关闭
        exclude: shutdown
  server:
    # 另开局域网端口
    port: 8889

Swagger

  • 正式环境关闭
  • 关闭忽略鉴权路径
yml
# Swagger界面内容配置
swagger:
  enable: false
  title: Gis Boot 平台接口文档
  description: gisboot Api Documentation
  version: 1.0.0
  termsOfServiceUrl: http://www.ztgis.com
  contact:
    name: zonetop
    url: http://www.ztgis.com
    email: http://www.ztgis.com