码迷,mamicode.com
首页 > 移动开发 > 详细

application和yml的区分

时间:2019-12-16 14:48:46      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:同时存在   alias   ack   between   xxx   state   数据源   test   tom   

区别

1.内容格式比较:
.properties文件,通过.来连接,通过=来赋值,结构上,没有分层的感觉,但比较直接。
.yml文件,通过:来分层,结构上,有比较明显的层次感,最后key赋值的:后需要留一个空格

2.执行顺序
如果工程中同时存在application.properties文件和 application.yml文件,yml文件会先加载,而后加载的properties文件会覆盖yml文件。所以建议工程中,只使用其中一种类型的文件即可。

举例

1.yml文件的好处,天然的树状结构,一目了然,实质上跟properties是差不多的。

2.key后面的冒号,后面一定要跟一个空格

#application.yml
 
server:
  port: 8086
  
spring:
    datasource:
        name: test
        url: jdbc:mysql://192.168.1.112:3306/test
        username: root
        password: xxx
        # 使用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
#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=root

application和yml的区分

标签:同时存在   alias   ack   between   xxx   state   数据源   test   tom   

原文地址:https://www.cnblogs.com/sharonzhang/p/12049009.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!