2021-08-02 16:31:22 +08:00
|
|
|
|
---
|
2021-09-01 17:53:07 +08:00
|
|
|
|
title: 2.配置文件详解
|
2021-08-02 16:31:22 +08:00
|
|
|
|
description: yml配置文件详解
|
|
|
|
|
published: true
|
2021-12-08 17:20:44 +08:00
|
|
|
|
date: 2021-12-08T09:20:42.544Z
|
2021-08-02 16:35:11 +08:00
|
|
|
|
tags: wg-basic
|
2021-08-02 16:31:22 +08:00
|
|
|
|
editor: markdown
|
|
|
|
|
dateCreated: 2021-07-29T06:22:48.973Z
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# 配置说明
|
|
|
|
|
## 环境
|
|
|
|
|
在SpringBoot中,配置文件默认为application.yml,相对于不同的环境(开发、测试、生产)开发人员可以对配置文件添加后缀来区分,具体如下:
|
|
|
|
|
|
|
|
|
|
1. **-dev**,开发环境
|
|
|
|
|
2. **-test**,测试环境
|
|
|
|
|
3. **-prod**,生产环境
|
|
|
|
|
4. **-XXX**,用户自定义
|
|
|
|
|
|
|
|
|
|
在运行服务时,只需要选择对应的环境即可,参数为`-Dspring.profiles.active=xxx`,如:`-Dspring.profiles.active=prod`表示服务在启动时会优先读取`application-prod.yml`配置文件,如果该文件不存在,则会读取`application.yml`文件。
|
|
|
|
|
|
|
|
|
|
## 属性拼写
|
|
|
|
|
yaml配置文件中,配置属性为小写的单词并以英文减号`-`进行连接,在配置文件解析的时候,SpringBoot会自动将`-`去除,并将除首单词之外的其余单词首字母进行大写,组合成**驼峰**模式。当然,配置文件也是支持驼峰模式描述属性的。
|
|
|
|
|
|
|
|
|
|
# Yaml与配置类对应关系
|
|
|
|
|
## 服务配置
|
|
|
|
|
属性类:ServerProperties
|
|
|
|
|
|
|
|
|
|
对照关系如下表所示
|
|
|
|
|
|
|
|
|
|
| 配置 | 属性 | 说明 | 必填 | 默认值 |
|
|
|
|
|
|:-:|:-:|:-:|:-:|:-:|
|
|
|
|
|
| server.port | port | 服务端口 | Y | 无 |
|
|
|
|
|
| server.url | url | 访问地址,如果前置由Nginx,则填写Nginx代理后的地址 | Y | 无 |
|
|
|
|
|
| server.system-title | systemTitle | 系统主标题 | Y | 无 |
|
|
|
|
|
| server.system-sub-title | systemSubTitle | 系统副标题 | N | 无 |
|
|
|
|
|
| server.default-index-page | defaultIndexPage | 设置后,访问index接口会重定向到配置的地址,index接口为登录后跳转的地址 | N | 无 |
|
|
|
|
|
| server.default-home-page | defaultHomePage | 设置后,访问default-home接口会重定向到配置的地址,default-home接口为默认index页面的首页 | N | 无 |
|
|
|
|
|
|
|
|
|
|
示例
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
server:
|
|
|
|
|
port: 8080
|
|
|
|
|
url: http://192.168.1.100:8080/xxx
|
|
|
|
|
system-title: XXX系统
|
|
|
|
|
system-sub-title: 系统
|
2021-10-12 15:11:35 +08:00
|
|
|
|
default-index-page: route/system/index
|
2021-08-02 16:31:22 +08:00
|
|
|
|
default-home-page: route/system/default
|
|
|
|
|
servlet:
|
|
|
|
|
# 该属性表示访问系统的上下文地址,如url中所示,xxx即为上下文地址
|
|
|
|
|
context-path: /xxx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 基础配置
|
|
|
|
|
属性类:ink.wgink.properties.BaseProperties
|
|
|
|
|
|
|
|
|
|
对照关系如下表所示
|
|
|
|
|
|
|
|
|
|
| 配置 | 属性 | 说明 | 必填 | 默认值 |
|
|
|
|
|
|:-:|:-:|:-:|:-:|:-:|
|
|
|
|
|
| spring.login-url | loginUrl | 登录页面的访问地址 | Y | /oauth/login |
|
|
|
|
|
| spring.login-failure | loginFailure | 登录失败后的处理地址 | Y | /oauth/login?error |
|
|
|
|
|
| spring.login-process | loginProcess | 登录时form表单提交的地址 | Y | /userlogin |
|
|
|
|
|
| spring.assets-matchers | assetsMatchers | 资源匹配路径 | Y | /assets/** |
|
|
|
|
|
|
|
|
|
|
示例
|
|
|
|
|
```yaml
|
|
|
|
|
spring:
|
|
|
|
|
login-url: /oauth/login
|
|
|
|
|
login-failure: /oauth/login?error
|
|
|
|
|
login-process: /userlogin
|
|
|
|
|
assets-matchers: /assets/**
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 访问控制配置
|
|
|
|
|
属性类:ink.wgink.properties.AccessControlProperties
|
|
|
|
|
|
|
|
|
|
对照关系如下表所示
|
|
|
|
|
|
|
|
|
|
| 配置 | 属性 | 说明 | 必填 | 默认值
|
|
|
|
|
|:-:|:-:|:-:|:-:|:-:|
|
|
|
|
|
| access-control.role-permission | rolePermission | 是否校验增、删、改、查、权限,关闭后,所有接口除菜单之外均可以正常访问 | N | true |
|
|
|
|
|
| access-control.pass-paths | passPaths | 放行的接口链接,支持Ant格式 | N | |
|
|
|
|
|
|
|
|
|
|
示例
|
|
|
|
|
```yaml
|
|
|
|
|
access-control:
|
|
|
|
|
role-permission: false
|
|
|
|
|
pass-paths:
|
|
|
|
|
- /abc/*/a
|
|
|
|
|
- /bac/**
|
|
|
|
|
- /cde/*
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Swagger文档
|
|
|
|
|
配置类:ink.wgink.common.config.SwaggerConfig
|
|
|
|
|
|
|
|
|
|
| 配置 | 属性 | 说明 | 必填 | 默认值
|
|
|
|
|
|:-:|:-:|:-:|:-:|:-:|
|
|
|
|
|
| swagger.title | title | 标题 | N | 相关接口文档 |
|
|
|
|
|
| swagger.description | description | 文档描述 | N | 相关接口文档 |
|
|
|
|
|
| swagger.service-url | serviceUrl | 业务地址 | N | |
|
|
|
|
|
| swagger.version | version | 文档版本 | N | 1.0 |
|
|
|
|
|
| swagger.base-package-list | basePackageList | 加载文档的根路径,不同的根路径用`,`(英文逗号)分割,如com.cm,ink.wgink | Y | |
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
swagger:
|
2021-10-12 15:11:54 +08:00
|
|
|
|
title: 标题
|
2021-08-02 16:31:22 +08:00
|
|
|
|
description: 描述
|
|
|
|
|
service-url: 业务地址
|
|
|
|
|
version: 1.0
|
|
|
|
|
base-package-list: ink.wgink,com.cm
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-11 10:15:53 +08:00
|
|
|
|
UI访问地址
|
|
|
|
|
- 原版:/swagger-ui.html
|
|
|
|
|
- 美化:/doc.html
|
|
|
|
|
|
2021-10-22 14:17:37 +08:00
|
|
|
|
## 即时消息
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
websocket:
|
|
|
|
|
url: 127.0.0.1
|
|
|
|
|
port: 8081
|
|
|
|
|
context: websocket
|
2021-12-08 16:30:16 +08:00
|
|
|
|
is-encrypt: false
|
2021-12-08 16:36:43 +08:00
|
|
|
|
aes-key: 1234567812345678
|
2021-10-22 14:17:37 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
| 配置 | 属性 | 说明 | 必填 | 默认值
|
|
|
|
|
|:-:|:-:|:-:|:-:|:-:|
|
|
|
|
|
| websocket.url | url | 访问地址 | N | 127.0.0.1 |
|
|
|
|
|
| websocket.port | port | 访问端口 | N | 1991 |
|
|
|
|
|
| websocket.context | context | 上下文 | N | websocket |
|
2021-12-08 16:30:16 +08:00
|
|
|
|
| websocket.is-encrypt | isEncrypt | 数据是否加密 | N | false |
|
2021-12-08 16:36:43 +08:00
|
|
|
|
| websocket.aes-key | aesKey | 长度为16位aes加密秘钥,当is-encrypt 为true时有效 | N | |
|
2021-10-22 14:17:37 +08:00
|
|
|
|
|
2021-10-22 14:23:40 +08:00
|
|
|
|
## 短信
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
# 短信服务
|
|
|
|
|
sms:
|
|
|
|
|
active: false
|
|
|
|
|
type: default
|
|
|
|
|
default-sms:
|
|
|
|
|
account: 账号
|
|
|
|
|
password: 密码
|
|
|
|
|
sign: 【标注】
|
|
|
|
|
template:
|
|
|
|
|
verification-code: '{sign} 您的验证码为 {content}, 有效时间为120秒,若非本人操作,请忽略。'
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
| 配置 | 属性 | 说明 | 必填 | 默认值
|
|
|
|
|
|:-:|:-:|:-:|:-:|:-:|
|
|
|
|
|
| sms.active | active | 是否激活 | N | false |
|
|
|
|
|
| sms.type | type | 短信模块类型,目前只支持default | N | default |
|
|
|
|
|
| sms.default-sms.account | defaultSms.account | 发送短信的账号 | Y | |
|
|
|
|
|
| sms.default-sms.password | defaultSms.password | 发送短信的密码 | Y | |
|
|
|
|
|
| sms.default-sms.sign | defaultSms.password | 签名,必须用【】包含 | Y | |
|
|
|
|
|
| sms.default-sms.template.verification-code | template.verficationCode | 验证码模板,{sign} 会替换配置的签名,{content} 会替换为短信内容 | Y | |
|
2021-10-22 14:18:21 +08:00
|
|
|
|
|
2021-08-02 16:31:22 +08:00
|
|
|
|
# 完整示例
|
|
|
|
|
```yml
|
|
|
|
|
server:
|
|
|
|
|
port: 8080
|
|
|
|
|
url: http://127.0.0.1:8080/xxx
|
|
|
|
|
system-title: XXX系统
|
|
|
|
|
system-sub-title: XXX系统
|
|
|
|
|
servlet:
|
|
|
|
|
context-path: /xxx
|
|
|
|
|
|
|
|
|
|
spring:
|
|
|
|
|
login-url: /oauth/login
|
|
|
|
|
login-failure: /oauth/login?error
|
|
|
|
|
login-process: /userlogin
|
|
|
|
|
assets-matchers: /assets/**
|
|
|
|
|
thymeleaf:
|
|
|
|
|
prefix: classpath:/templates/
|
|
|
|
|
suffix: .html
|
|
|
|
|
mode: HTML5
|
|
|
|
|
encoding: UTF-8
|
|
|
|
|
cache: false
|
|
|
|
|
main:
|
|
|
|
|
allow-bean-definition-overriding: true
|
|
|
|
|
servlet:
|
|
|
|
|
multipart:
|
|
|
|
|
max-file-size: 1GB
|
|
|
|
|
max-request-size: 1GB
|
|
|
|
|
datasource:
|
|
|
|
|
druid:
|
2021-09-01 11:27:02 +08:00
|
|
|
|
url: jdbc:mysql://127.0.0.1:3306/db_xxx?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC&nullCatalogMeansCurrent=true
|
2021-08-02 16:31:22 +08:00
|
|
|
|
db-type: mysql
|
|
|
|
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
|
|
|
|
username: root
|
|
|
|
|
password: root
|
|
|
|
|
initial-size: 2
|
|
|
|
|
min-idle: 2
|
|
|
|
|
max-active: 5
|
|
|
|
|
max-wait: 60000
|
|
|
|
|
time-between-eviction-runs-millis: 60000
|
|
|
|
|
min-evictable-idle-time-millis: 300000
|
|
|
|
|
validation-query: SELECT 1 FROM DUAL
|
|
|
|
|
test-while-idle: true
|
|
|
|
|
test-on-borrow: false
|
|
|
|
|
test-on-return: false
|
|
|
|
|
pool-prepared-statements: true
|
|
|
|
|
max-pool-prepared-statement-per-connection-size: 10
|
|
|
|
|
filter:
|
|
|
|
|
commons-log:
|
|
|
|
|
connection-logger-name: stat,wall,log4j
|
|
|
|
|
stat:
|
|
|
|
|
log-slow-sql: true
|
|
|
|
|
slow-sql-millis: 2000
|
|
|
|
|
connection-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
|
|
|
|
|
use-global-data-source-stat: true
|
|
|
|
|
|
|
|
|
|
# 数据库
|
|
|
|
|
mybatis:
|
|
|
|
|
config-location: classpath:mybatis/mybatis-config.xml
|
|
|
|
|
mapper-locations: classpath*:mybatis/mapper/**/*.xml
|
|
|
|
|
|
|
|
|
|
# 文档
|
|
|
|
|
swagger:
|
|
|
|
|
base-package-list: ink.wgink,com.cm
|
|
|
|
|
|
|
|
|
|
# 访问控制
|
|
|
|
|
access-control:
|
|
|
|
|
role-permission: false
|
|
|
|
|
|
|
|
|
|
# 文件
|
|
|
|
|
file:
|
|
|
|
|
# 文件的保存路径
|
|
|
|
|
upload-path: /a/b/c/UploadFiles/
|
|
|
|
|
# 图片类型
|
|
|
|
|
image-types: png,jpg,jpeg,gif,blob
|
|
|
|
|
# 视频类型
|
|
|
|
|
video-types: mp4,rmvb
|
|
|
|
|
# 音频类型
|
|
|
|
|
audio-types: mp3,wmv,amr
|
|
|
|
|
# 文件类型
|
|
|
|
|
file-types: doc,docx,xls,xlsx,ppt,pptx,txt,zip,rar,apk,pdf
|
|
|
|
|
# 同时上传最大支持数
|
|
|
|
|
max-file-count: 6
|
|
|
|
|
# 图片输出压缩质量,大于0,默认0.4
|
|
|
|
|
image-output-quality: 0.4
|
2021-12-08 16:30:16 +08:00
|
|
|
|
# 启用minIo
|
|
|
|
|
use-min-io: false
|
|
|
|
|
# 与use-min-io配套使用
|
|
|
|
|
min-io:
|
|
|
|
|
# minio服务位置
|
|
|
|
|
endpoint: http://192.168.0.188:19001
|
|
|
|
|
# minio用户名
|
|
|
|
|
access-key: demotest
|
|
|
|
|
# minio 密码
|
|
|
|
|
secret-key: demotest
|
2021-08-02 16:31:22 +08:00
|
|
|
|
|
|
|
|
|
# 日志
|
|
|
|
|
logging:
|
|
|
|
|
file:
|
|
|
|
|
# 日志文件的路径,不设置不生成日志文件
|
|
|
|
|
name: /a/b/c/xxx-logs.log
|
|
|
|
|
level:
|
|
|
|
|
root: error
|
|
|
|
|
ink.wgink: debug
|
|
|
|
|
com.cm: debug
|
|
|
|
|
```
|