擴展:配置文件

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!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章