1、基本语法
K:(空格,必须有)V
2、配置自定义属性:
user: name:username: zsrealname: ls使用:@Value("${user.name.username:zz}")//:zz的含义是若配置文件中username无对应值则使用zz作为默认值private String USERNAME;
3、环境配置
spring: application:name: application profiles:active: dev #开发环境---
server:port: 8080
spring: profiles: dev #开发环境servlet: multipart:maxFileSize: 50MBmaxRequestSize: 50MBhttp: #编码设置encoding:charset: UTF-8enabled: trueforce: true jackson: #时间格式转换date-format: yyyy-MM-dd HH:mm:ss time-zone: GMT+8 datasource:db1: #数据源1jdbc-url: jdbc:mysql://192.168.91.129:3306/db1?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=falseusername: rootpassword: rootdriver-class-name: com.mysql.jdbc.DrivermaxIdle: 50 maxWait: 30minIdle: 20maxActive: 500validationQuery: SELECT 1type: org.apache.commons.dbcp2.BasicDataSourcedb2: #数据源2jdbc-url: jdbc:mysql://192.168.91.129:3306/db2?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=falseusername: rootpassword: rootdriver-class-name: com.mysql.jdbc.DrivermaxIdle: 50 maxWait: 30minIdle: 20maxActive: 500validationQuery: SELECT 1type: org.apache.commons.dbcp2.BasicDataSourcejpa: #JPA配置database: MYSQLshow-sql: falseproperties: hibernate: dialect: org.hibernate.dialect.MySQL5Dialectdatabase-platform: org.hibernate.dialect.MySQL5InnoDBDialect #方言
若要配置其他环境,重复--- 下的内容,更改profiles: test即可