springboot中application.properties 改成 application.yml详解

来源:互联网 发布:阿里云 mongodb 连接 编辑:程序博客网 时间:2024/06/06 09:25

欢迎扫码加入Java高知群交流


springboot官方推荐使用application.yml配置文件,yml文件的好处,天然的树状结构,一目了然。使用的时候需要注意一些细节的地方:

原有的key,例如spring.jpa.properties.hibernate.dialect,按“.”分割,都变成树状的配置,key后面的冒号,后面一定要跟一个空格。

下面对比两个文件

application.properties:

server.port=8080server.session-timeout=30server.context-path=server.tomcat.max-threads=0server.tomcat.uri-encoding=UTF-8spring.datasource.url = jdbc:mysql://localhost:3306/springspring.datasource.username = rootspring.datasource.password = rootspring.datasource.driverClassName = com.mysql.jdbc.Driver# Specify the DBMSspring.jpa.database = MYSQL# Show or not log for each sql queryspring.jpa.show-sql = true# Hibernate ddl auto (create, create-drop, update)spring.jpa.hibernate.ddl-auto = update# Naming strategyspring.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


application.yml:

server:  port: 8080  session-timeout: 30  tomcat.max-threads: 0  tomcat.uri-encoding: UTF-8spring:  datasource:    url : jdbc:mysql://localhost:3306/springboot    username : root    password : root    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

The end!


欢迎扫码加入Java高知群交流


阅读全文
1 0
原创粉丝点击