application properties 檔案和 application yml 檔案有什麼區別呢
阿新 • • 發佈:2018-11-17
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
application.properties 檔案和 application.yml 檔案有什麼區別呢?
yml檔案的好處,天然的樹狀結構,一目瞭然,實質上跟properties是差不多的。
官方給的很多demo,都是用yml檔案配置的。
注意點:
1,原有的key,例如spring.jpa.properties.hibernate.dialect,按“.”分割,都變成樹狀的配置
2,key後面的冒號,後面一定要跟一個空格
3,把原有的application.properties刪掉。然後一定要執行一下 maven -X clean install
示例:
#application.ymlserver: 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
你可能還會關注: Spring Boot application.yml application.properties 優先順序#application.propertiesserver.port=8085spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSourcespring.datasource.url=jdbc:mysql://aliyuncs.com:3306/home?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=truespring.datasource.username=rootspring.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.modelspring.mvc.view.prefix=/WEB-INF/jsp/spring.mvc.view.suffix=.jspspring.druid.datasource.type=com.alibaba.druid.pool.DruidDataSourcespring.druid.datasource.driverClassName=com.mysql.jdbc.Driverspring.druid.datasource.url=jdbc:mysql://localhost:3306/spring_boot?characterEncoding=utf-8spring.druid.datasource.username=rootspring.druid.datasource.password=xxx