Appearance
YML 配置文件
文件位置

yml 文件用途
- application.yml: 全局配置文件
- application-dev.yml: 开发时使用的配置文件
- application-test.yml: 测试时使用的配置文件
- application-preview.yml: 演示时使用的配置文件
- application-pro.yml: 生产时使用的配置文件
application.yml: 全局配置文件
spring
yaml
spring:
#环境 dev|test|pro|preview
profiles:
active: dev
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
enabled: true
mvc:
hiddenmethod:
filter:
enabled: true
jackson:
serialization:
write-dates-as-timestamps: true
time-zone: GMT+8
main:
allow-bean-definition-overriding: true
- spring.profiles.active=
*
*
正好匹配 application-*
.yml 配置文件,app 启动时,项目会先从 application-*
.yml 加载配置。 - spring.servlet.multipart.max-file-size: 表示该系统上传单个文件最大数据大小 spring.servlet.multipart.max-request-size: 表示该系统总上传数据的总大小 spring.servlet.multipart.enabled: 表示是否开启该配置
- spring.mvc.hiddenmethod.filter.enabled: 表示是否启用 hiddenMethod 过滤器 hiddenMethod 过滤器作用: 浏览器只支持 Post 和 get 的方式,想要实现 delete 和 put 的方式,即实现 Rest 风格的 url,就需要使用该过滤器
- spring.jackson.serialization.write-dates-as-timestamps: 表示是否将该系统的 data 自动改为时间戳 spring.jackson.time-zone=GMT+8: 表示设置全局时区为东八区时间
- spring.main.allow-bean-definition-overriding: 表示是否允许使用相同名称重新注册不同的 bean
config 系统内部配置
yaml
config:
WebAnnexFilePath: WebAnnexFile
DataBackupFilePath: DataBackupFile
TemporaryFilePath: TemporaryFile
SystemFilePath: SystemFile
TemplateFilePath: TemplateFile
EmailFilePath: EmailFile
DocumentFilePath: DocumentFile
DocumentPreviewPath: DocumentPreview
UserAvatarFilePath: UserAvatar
IMContentFilePath: IMContentFile
MPMaterialFilePath: MPMaterial
TemplateCodePath: TemplateCode
BiVisualPath: BiVisualPath
SysConfigPath: SysConfig
ArcgisPath: ArcGISExe
MPUploadFileType: bmp,png,jpeg,jpg,gif,mp3,wma,wav,amr,mp4
WeChatUploadFileType: jpg,png,doc,docx,ppt,pptx,xls,xlsx,pdf,txt,rar,zip,csv,amr,mp4
AllowUploadImageType: jpg,gif,png,bmp,jpeg,tiff,psd,swf,svg,pcx,dxf,wmf,emf,lic,eps,tga
AllowUploadFileType: jpg,gif,png,bmp,jpeg,doc,docx,ppt,pptx,xls,xlsx,pdf,txt,rar,zip,csv
#代码生成器模块命名
CodeAreasName: example
#===============系统错误邮件报告反馈相关==================
SoftName: ztgis-java-boot
SoftFullName: ztgis软件开发平台
AppVersion: V3.2.4
AppUpdateContent: ;
# 当前域名配置(文档预览中使用)
Domain: http://localhost:30000
#=====================================
RecordLog: true
ErrorReport: false
ErrorReportTo: surrpot@yinmaisoft.com
#多租户是否开启
MultiTenancy: false
MultiTenancyUrl: http://127.0.0.1:30006/api/tenant/DbName/
IgexinEnabled: true
IgexinAppid: HLFY9T2d1z7MySY8hwGwh4
IgexinAppkey: 6Uiduugq648YDChhCjAt59
IgexinMastersecret: pEyQm156SJ9iS7PbyjLCZ6
SoftVersion: V3.2.4
#===============跨域配置==================
Origins: http://127.0.0.1,http://localhost,http://127.0.0.1:3232,http://192.168.1.113,
Methods: GET,HEAD,POST,PUT,DELETE,OPTIONS
#============yozo===========
# 永中office在线预览配置
YozoDomain: //dcsapi.com/
YozoDomainKey: 57462250284462899305150
YozoCloudDomain: //dmc.yozocloud.cn
YozoAppId: yozoAgR41jgC0062
YozoAppKey: fc3134a9ba8bc6f4c69d635f9adf
YozoEditDomain: //eic.yozocloud.cn
# 增补属性
isIpCity: 0 # 登录时是否获取ip的城市信息,会发起互联网请求,内网配置为0,
- 静态资源配置及基础配置
静态资源配置及基础配置 | 作用 |
---|---|
WebAnnexFilePath: WebAnnexFile | 前端附件文件目录 |
DataBackupFilePath: DataBackupFile | 数据库备份文件路径 |
TemporaryFilePath: TemporaryFile | 临时文件存储路径 |
SystemFilePath: SystemFile | 系统文件存储路径 |
TemplateFilePath: TemplateFile | 文件模板存储路径 |
EmailFilePath: EmailFile | 邮件文件存储路径 |
DocumentFilePath: DocumentFile | 文档管理存储路径 |
DocumentPreviewPath: DocumentPreview | 文件在线预览存储 pdf |
UserAvatarFilePath: UserAvatar | 用户头像存储路径 |
IMContentFilePath: IMContentFile | IM 聊天图片+语音存储路径 |
MPMaterialFilePath: MPMaterial | 微信公众号资源文件存储路径 |
TemplateCodePath: TemplateCode | 代码模板存储路径 |
BiVisualPath: BiVisualPath | 大屏图片存储目录 |
SysConfigPath: SysConfig | 系统的配置文件存放目录,例如存放不动产接口的 json 配置文 |
ArcgisPath: ArcGISExe | arcgis EXE 文件夹 |
MPUploadFileType: bmp,png,jpeg,jpg,gif,mp3,wma,wav,amr,mp4 | 微信公众号允许上传文件类型 |
WeChatUploadFileType: jpg,png,doc,docx,ppt,pptx,xls,xlsx,pdf,txt,rar,zip,csv,amr,mp4 | 微信允许上传文件类型 |
AllowUploadImageType: jpg,gif,png,bmp,jpeg,tiff,psd,swf,svg,pcx,dxf,wmf,emf,lic,eps,tga | 允许图片类型 |
AllowUploadFileType: jpg,gif,png,bmp,jpeg,doc,docx,ppt,pptx,xls,xlsx,pdf,txt,rar,zip,csv | 允许上传文件类型 |
CodeAreasName: example | 代码生成器模块命名 |
- 新增配置步骤: 在配置文件的 config 下新增属性之后,就在
ztgis-common/src/main/java/ztgis/config/ConfigValueUtil.java
文件中增加以下声明,如:
java
@Value("${config.WebAnnexFilePath}")
private String webAnnexFilePath;
- 使用方法
java
@Autowired
private ConfigValueUtil configValueUtil;
configValueUtil.getWebAnnexFilePath()
- 系统错误邮件报告反馈相关
yaml
config
#===============系统错误邮件报告反馈相关==================
SoftName: ztgis-java-boot
SoftFullName: ztgis软件开发平台
AppVersion: V3.2.4
AppUpdateContent: ;
# 当前域名配置(文档预览中使用)
Domain: http://localhost:30000
#=====================================
RecordLog: true
ErrorReport: false
ErrorReportTo: surrpot@yinmaisoft.com
#多租户是否开启
MultiTenancy: false
MultiTenancyUrl: http://127.0.0.1:30006/api/tenant/DbName/
IgexinEnabled: true
IgexinAppid: HLFY9T2d1z7MySY8hwGwh4
IgexinAppkey: 6Uiduugq648YDChhCjAt59
IgexinMastersecret: pEyQm156SJ9iS7PbyjLCZ6
SoftVersion: V3.2.4
- 跨域配置
yaml
config
#===============跨域配置==================
Origins: http://127.0.0.1,http://localhost,http://127.0.0.1:3232,http://192.168.1.113,
Methods: GET,HEAD,POST,PUT,DELETE,OPTIONS
- 永中office在线预览配置
yaml
config
#============yozo===========
# 永中office在线预览配置
YozoDomain: //dcsapi.com/
YozoDomainKey: 57462250284462899305150
YozoCloudDomain: //dmc.yozocloud.cn
YozoAppId: yozoAgR41jgC0062
YozoAppKey: fc3134a9ba8bc6f4c69d635f9adf
YozoEditDomain: //eic.yozocloud.cn
application-*.yml: 各种场景下的配置文件
spring-boot 整合 jasypt 加密 yml 配置文件
通常项目配置文件中的账号信息如下,都是直接暴露出来的,如果源码不小心泄露将会引起一系列安全问题
yaml
jasypt:
encryptor:
password: ztgis #加解密秘钥
algorithm: PBEWithMD5AndDES #默认算法
iv-generator-classname: org.jasypt.iv.NoIvGenerator
步骤:
- 工程引入依赖
xml
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot</artifactId>
<version>3.0.2</version>
</dependency>
在spring-boot中application-*.yml 配置 jsaypt
生成加密密钥 在
ztgis-common/src/main/java/ztgis/util/JasyptUtil.java
文件下生成,代码如下:
java
* @param password 配置文件中设定的加密密码 jasypt.encryptor.password
* @param value 待加密值
public static void main(String[] args){
System.out.println(encyptPwd(password, value));
}
- 更换数据库用户和密码为加密密码
yaml
spring:
# 数据源配置
datasource:
master:
# 共用配置
username: ztgis
password: ENC(Jb1Yv5tBdfWAaJVEUSKsmg==)
数据源配置
yaml
spring:
# 数据源配置
datasource:
master:
# 原框架数据库配置,涉及的到太多,没办法删除
dbtype: Oracle
dbname: PDBORCL
host: 192.168.3.210
port: 1521
# 表空间(当数据库为Oracle、达梦DM8、金仓KingbaseES时表空间必须指定,其他数据库为空即可)
tablespace: ztgis
# 共用配置
username: ztgis
password: ENC(Jb1Yv5tBdfWAaJVEUSKsmg==)
# 多数据源配置
jdbcUrl: jdbc:oracle:thin:@//192.168.3.210/pdborcl
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: oracle.jdbc.OracleDriver
slave2:
dbtype: Oracle
dbname: PDBORCL
host: 192.168.3.210
port: 1521
# 表空间(当数据库为Oracle、达梦DM8、金仓KingbaseES时表空间必须指定,其他数据库为空即可)
tablespace: XM_BDCDC_WS_TLW
# 共用配置
username: XM_BDCDC_WS_TLW
password: ENC(ScfQHDnNLpDNcCPZqbMWikIvBT8ZaF7c) #XM_BDCDC_WS_TLW
# 多数据源配置
jdbcUrl: jdbc:oracle:thin:@//192.168.3.210:1521/pdborcl
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: oracle.jdbc.OracleDriver
- 使用方法
多数据源事务只能使用MoreTransaction
java
// 方法上使用注解,可指定数据源
@MoreTransaction({"slave2", "master"})
Redis 配置
yaml
spring:
# Redis配置
redis:
database: 5 # Redis数据库索引(默认为0)
host: 127.0.0.1 # Redis服务器地址
port: 6379 # Redis服务器端口号
password:
timeout: 3000 # 连接超时时长(毫秒)
lettuce:
pool:
max-active: 8 # 连接池最大连接数
max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)
min-idle: 0 # 连接池中的最小空闲连接
max-idle: 8 # 连接池中的最大空闲连接
config
yaml
config:
# Windows配置(静态资源根目录和代码生成器临时目录)
Path: E:\svn\ztgis\code\static\ztgis-resources\
ServiceDirectoryPath: E:\svn\ztgis\trunk\code_unit\code\static\ztgis-resources\CodeTemp\
# MAC配置(静态资源根目录和代码生成器临时目录)
# Path: ztgis-resources/
# ServiceDirectoryPath: ztgis-resources/CodeTemp/
# Linux配置(静态资源根目录和代码生成器临时目录)
# Path: /www/wwwroot/Resources/
# ServiceDirectoryPath: /www/wwwroot/Resources/CodeTemp/
#是否开启测试环境
TestVersion: false
#登录模式,是否开启并行登录
ParallelLogin: true
# 文件存储类型(local-本地存储,minio-网络存储)
fileType: local
使用 minio 时配置
分布式 项目中应用
yaml
ztgis:
# 使用minio时配置
minio:
endpoint: http://192.168.0.147:9000
accessKey: minioadmin
secretKey: minioadmin
fileHost: http://192.168.0.147:9000
systemCode系统编码
- 用于启动服务时获取系统要运行的定时器使用(空或者当前指定的这个系统编码)
yaml
ztgis:
systemCode: apply
Swagger 界面内容配置
- 正式环境关闭
- 关闭对应忽略鉴权页面
yaml
springfox:
documentation:
# 总开关(同时设置auto-startup=false,否则/v3/api-docs等接口仍能继续访问)
enabled: true
auto-startup: false
swagger-ui:
enabled: true
SM4配置
登录等场景加密使用
yaml
ztgis:
sm4-key: key #key 需CryptoHexDES工具 加密
sm4-iv: iv #iv 需CryptoHexDES工具 加密
密码策略配置
密码安全规范
yaml
ztgis:
secure:
#优先级:如何type和length同时大于0,则启用passwordType与passwordLength 模式,否则启用passwordMode模式)
#不启用密码强度校验:passwordMode:1,并且passwordType:0
#三个数据均未配置则使用 模式3
#字符类型:数字、大写字母、小写字母、特殊字符
passwordMode: 3 # 密码强度模式,1、不限制,2、2种以上字符长度大于8;3、3种以上字符且长度大于10
passwordType: 3 # 几种字符类型,范围【0,1,2,3,4】
passwordLength: 10 # 密码长度
# 密码过期策略
passwordExpire: true # 是否启用密码过期
passwordExpireTime: 90 # 过期时间(天)
# 密码修改策略
passwordSameWithLast: false # 修改密码 是否允许与上一次一致
登录失败账户锁定配置
yaml
ztgis:
secure:
# 限制用户登陆错误次数(次)
loginTimesLimit: 5
# 错误超过次数后多少分钟后才能继续登录(分钟)
loginLimitTime: 30
Jar 授权日期配置
DesUtil 加密,加密前格式YYYY—MM-DD
yaml
ztgis:
expiration: xxxx# jar包过期时间
忽略鉴权配置
yaml
ignored:
login: true #是否需要登录
urls:
- /api/oauth/Login
- /api/oauth/QuickLogin
- /api/file/Uploader/**
- /api/file/Download/**
- /api/visualdev/Generater/DownloadVisCode/**
- /api/file/DownloadModel/**
- /api/file/Image/**
- /api/file/ImageCode/**
- /api/extend/DocumentPreview/**
- /api/visualdev/DataScreen/Images/**
- /api/extend/DocumentPreview/down/{fileName}
- /api/system/DataMap/**
- /api/file/**
- /api/file/onlinePreview
- /api/scheduleTaskLog/**
# 大屏图片
- /api/file/VisusalImg/**
- /api/blade-visual/map/data
- /api/blade-visual/visual/put-file/**
# 避免拦截/websocket链接
- /message/websocket
- /api/system/DictionaryData/{dictionaryTypeId}/Data/Selector
# - /swagger-ui/index.html
# - /swagger-resources/**
- /webjars/**
- /v3/**
# - /swagger-ui/**
- /api/system/DataMap/{id}/Data
- /api/system/DataInterface/{id}/Actions/Response
# 部分业务接口
- 部分业务接口
跨域配置
yaml
allow-origin:
urls:
- "*"
- "http://127.0.0.1"
- "http://a.b.c"
- "xxxxxx"