扩展:配置文件

springboot官方推荐使用application.yml配置文件,yml文件的好处,天然的树状结构,一目了然。使用的时候需要注意一些细节的地方:
原有的key,例如spring.jpa.properties.hibernate.dialect,按“.”分割,都变成树状的配置,key后面的冒号,后面一定要跟一个空格。
下面对比两个文件
application.properties:
[plain]  view plain  copy
  1. server.port=8080  
  2. server.session-timeout=30  
  3. server.context-path=  
  4. server.tomcat.max-threads=0  
  5. server.tomcat.uri-encoding=UTF-8  
  6.   
  7. spring.datasource.url = jdbc:mysql://localhost:3306/spring  
  8. spring.datasource.username = root  
  9. spring.datasource.password = root  
  10. spring.datasource.driverClassName = com.mysql.jdbc.Driver  
  11. # Specify the DBMS  
  12. spring.jpa.database = MYSQL  
  13. # Show or not log for each sql query  
  14. spring.jpa.show-sql = true  
  15. # Hibernate ddl auto (create, create-drop, update)  
  16. spring.jpa.hibernate.ddl-auto = update  
  17. # Naming strategy  
  18. spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy  
  19.   
  20. # stripped before adding them to the entity manager)  
  21. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect  
application.yml:
[plain]  view plain  copy
  1. server:  
  2.   port: 8080  
  3.   session-timeout: 30  
  4.   tomcat.max-threads: 0  
  5.   tomcat.uri-encoding: UTF-8  
  6.   
  7. spring:  
  8.   datasource:  
  9.     url : jdbc:mysql://localhost:3306/springboot  
  10.     username : root  
  11.     password : root  
  12.     driverClassName : com.mysql.jdbc.Driver  
  13.   jpa:  
  14.     database : MYSQL  
  15.     show-sql : true  
  16.     hibernate:  
  17.       ddl-auto : update  
  18.       naming-strategy : org.hibernate.cfg.ImprovedNamingStrategy  
  19.     properties:  
  20.       hibernate:  
  21.         dialect : org.hibernate.dialect.MySQL5Dialect  

The end!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值