赞
踩
1、基本语法
K:(空格,必须有)V
2、配置自定义属性:
- user:
- name:
- username: zs
- realname: 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: 50MB
- maxRequestSize: 50MB
- http: #编码设置
- encoding:
- charset: UTF-8
- enabled: true
- force: true
- jackson: #时间格式转换
- date-format: yyyy-MM-dd HH:mm:ss
- time-zone: GMT+8
- datasource:
- db1: #数据源1
- jdbc-url: jdbc:mysql://192.168.91.129:3306/db1?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false
- username: root
- password: root
- driver-class-name: com.mysql.jdbc.Driver
- maxIdle: 50
- maxWait: 30
- minIdle: 20
- maxActive: 500
- validationQuery: SELECT 1
- type: org.apache.commons.dbcp2.BasicDataSource
- db2: #数据源2
- jdbc-url: jdbc:mysql://192.168.91.129:3306/db2?useUnicode=true&characterEncoding=UTF-8&tinyInt1isBit=false
- username: root
- password: root
- driver-class-name: com.mysql.jdbc.Driver
- maxIdle: 50
- maxWait: 30
- minIdle: 20
- maxActive: 500
- validationQuery: SELECT 1
- type: org.apache.commons.dbcp2.BasicDataSource
- jpa: #JPA配置
- database: MYSQL
- show-sql: false
- properties:
- hibernate:
- dialect: org.hibernate.dialect.MySQL5Dialect
- database-platform: org.hibernate.dialect.MySQL5InnoDBDialect #方言

若要配置其他环境,重复--- 下的内容,更改profiles: test即可
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。