springboot的application.properties與.yml的區別

來源:互聯網
上載者:User

標籤:javaee   span   url   clipboard   執行   upd   log   odi   utf-8   

現在我們的application.properties檔案內容是:

 

 

[plain] view plain copy    
  1. server.port=8090  
  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/newbirds  
  8. spring.datasource.username = root  
  9. spring.datasource.password = mymysql  
  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  


而官方給的很多demo,都是用yml檔案配置的。

 

yml檔案的好處,天然的樹狀結構,一目瞭然。不過當時把application.properties 改成 application.yml還是痛苦了一會兒。

下面是置換後的application.yml內容:

 

[plain] view plain copy    
  1. server:  
  2.   port: 8090  
  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/newbirds  
  10.     username : root  
  11.     password : mymysql  
  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  


注意點:

 

1,原有的key,例如spring.jpa.properties.hibernate.dialect,按“.”分割,都變成樹狀的配置

2,key後面的冒號,後面一定要跟一個空格

3,把原有的application.properties刪掉。然後一定要執行一下  maven -X clean install

springboot的application.properties與.yml的區別

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.