application.properties 改成 application.yml
阿新 • • 發佈:2019-02-17
現在我們的application.properties檔案內容是:
- server.port=8090
- server.session-timeout=30
- server.context-path=
- server.tomcat.max-threads=0
- server.tomcat.uri-encoding=UTF-8
- spring.datasource.url = jdbc:mysql://localhost:3306/newbirds
- spring.datasource.username = root
-
spring.datasource.password = mymysql
- spring.datasource.driverClassName = com.mysql.jdbc.Driver
- # Specify the DBMS
- spring.jpa.database = MYSQL
- # Show or not log for each sql query
- spring.jpa.show-sql = true
- # Hibernate ddl auto (create, create-drop, update)
- spring.jpa.hibernate.ddl-auto = update
- # Naming strategy
-
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
- # stripped before adding them to the entity manager)
- spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
而官方給的很多demo,都是用yml檔案配置的。
yml檔案的好處,天然的樹狀結構,一目瞭然。不過當時把application.properties 改成 application.yml還是痛苦了一會兒。
下面是置換後的application.yml內容:
- server:
- port: 8090
-
session-timeout: 30
- tomcat.max-threads: 0
- tomcat.uri-encoding: UTF-8
- spring:
- datasource:
- url : jdbc:mysql://localhost:3306/newbirds
- username : root
- password : mymysql
- driverClassName : com.mysql.jdbc.Driver
- jpa:
- database : MYSQL
- show-sql : true
- hibernate:
- ddl-auto : update
- naming-strategy : org.hibernate.cfg.ImprovedNamingStrategy
- properties:
- hibernate:
- dialect : org.hibernate.dialect.MySQL5Dialect
注意點:
1,原有的key,例如spring.jpa.properties.hibernate.dialect,按“.”分割,都變成樹狀的配置
2,key後面的冒號,後面一定要跟一個空格
3,把原有的application.properties刪掉。然後一定要執行一下 maven -X clean install