docs: update wg-basic-yml
This commit is contained in:
parent
e0a238c43f
commit
7445391401
210
wg-basic-yml.md
Normal file
210
wg-basic-yml.md
Normal file
@ -0,0 +1,210 @@
|
|||||||
|
---
|
||||||
|
title: 配置文件详解
|
||||||
|
description: yml配置文件详解
|
||||||
|
published: true
|
||||||
|
date: 2021-08-02T08:31:21.032Z
|
||||||
|
tags:
|
||||||
|
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: 系统
|
||||||
|
default-index-page: route/system/index
|
||||||
|
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:
|
||||||
|
title: 标题
|
||||||
|
description: 描述
|
||||||
|
service-url: 业务地址
|
||||||
|
version: 1.0
|
||||||
|
base-package-list: ink.wgink,com.cm
|
||||||
|
```
|
||||||
|
|
||||||
|
# 完整示例
|
||||||
|
```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:
|
||||||
|
url: jdbc:mysql://127.0.0.1:3306/db_xxx?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&autoReconnect=true&failOverReadOnly=false&useSSL=false&serverTimezone=UTC
|
||||||
|
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
|
||||||
|
|
||||||
|
# 日志
|
||||||
|
logging:
|
||||||
|
file:
|
||||||
|
# 日志文件的路径,不设置不生成日志文件
|
||||||
|
name: /a/b/c/xxx-logs.log
|
||||||
|
level:
|
||||||
|
root: error
|
||||||
|
ink.wgink: debug
|
||||||
|
com.cm: debug
|
||||||
|
```
|
Loading…
Reference in New Issue
Block a user