当前位置: 代码迷 >> 综合 >> Spring Boot的yml配置文件
  详细解决方案

Spring Boot的yml配置文件

热度:89   发布时间:2023-10-21 15:26:02.0

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即可

  相关解决方案