application.properties 文件和 application.yml 文件有什么区别呢?

application.properties  文件和 application.yml 文件有什么区别呢?

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

官方给的很多demo,都是用yml文件配置的。

注意点:

1,原有的key,例如spring.jpa.properties.hibernate.dialect,按“.”分割,都变成树状的配置

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

3,把原有的application.properties删掉。然后一定要执行一下  maven -X clean install

示例:

 

 
  1. #application.yml

  2.  
  3. server:

  4. port: 8086

  5.  
  6. spring:

  7. datasource:

  8. name: test

  9. url: jdbc:mysql://192.168.1.112:3306/test

  10. username: root

  11. password: xxx

  12. # 使用druid数据源

  13. type: com.alibaba.druid.pool.DruidDataSource

  14. driver-class-name: com.mysql.jdbc.Driver

  15. filters: stat

  16. maxActive: 20

  17. initialSize: 1

  18. maxWait: 60000

  19. minIdle: 1

  20. timeBetweenEvictionRunsMillis: 60000

  21. minEvictableIdleTimeMillis: 300000

  22. validationQuery: select 'x'

  23. testWhileIdle: true

  24. testOnBorrow: false

  25. testOnReturn: false

  26. poolPreparedStatements: true

  27. maxOpenPreparedStatements: 20

 

 
  1. #application.properties

  2.  
  3. server.port=8085

  4.  
  5. spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

  6. spring.datasource.url=jdbc:mysql://aliyuncs.com:3306/home?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true

  7. spring.datasource.username=root

  8. spring.datasource.password=***

  9. spring.datasource.driver-class-name=com.mysql.jdbc.Driver

  10.  
  11. #mybatis.mapper-locations=classpath*:com/wanyu/fams/mapping/*Mapper.xml

  12. #mybatis.type-aliases-package=com.wanyu.fams.model

  13.  
  14. spring.mvc.view.prefix=/WEB-INF/jsp/

  15. spring.mvc.view.suffix=.jsp

  16.  
  17. spring.druid.datasource.type=com.alibaba.druid.pool.DruidDataSource

  18. spring.druid.datasource.driverClassName=com.mysql.jdbc.Driver

  19. spring.druid.datasource.url=jdbc:mysql://localhost:3306/spring_boot?characterEncoding=utf-8

  20. spring.druid.datasource.username=root

  21. spring.druid.datasource.password=xxx

 

你可能感兴趣的:(springcloud)