版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a549654065/article/details/83593099
application.yml和application.properties文件这两种文件都是Springboot的配置文件,注释都可以用#号来注释,只不过因为application.yml看起来更直观,更清晰。但是要注意一点:properties文件的优先级高于yml文件,即如果两个文件中都配置了端口号,只有properties中的端口号有效,而yml文件中端口配置无效。
首先看application.properties文件,在properties文件中是以”.”进行分割的。
#application.properties
server.port=8085
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.url=jdbc:mysql://aliyuncs.com:3306/home?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true
spring.datasource.username=root
spring.datasource.password=***
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#mybatis.mapper-locations=classpath*:com/wanyu/fams/mapping/*Mapper.xml
#mybatis.type-aliases-package=com.wanyu.fams.model
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.druid.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.druid.datasource.driverClassName=com.mysql.jdbc.Driver
spring.druid.datasource.url=jdbc:mysql://localhost:3306/spring_boot?characterEncoding=utf-8
spring.druid.datasource.username=root
spring.druid.datasource.password=xxx
而application.properties文件,都是K-V格式,并且通过” : ”引号进行赋值;
server:
port: 8081
spring:
datasource:
name: test
url: jdbc:mysql://localhost:3306/springbootdatabase
username: root
password: 123456
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
也就是说
properties文件中
spring.druid.datasource.username=root
spring.druid.datasource.password=123456
spring.http.multipart.maxFileSize=100Mb
spring.http.multipart.maxRequestSize=100Mb
等于
yml文件中
spring:
datasource:
username: root
password: 123456
http:
multipart:
maxFileSize: 100Mb
maxRequestSize: 100Mb
注意:yml文件中