博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot的application.properties与.yml的区别
阅读量:7123 次
发布时间:2019-06-28

本文共 1487 字,大约阅读时间需要 4 分钟。

现在我们的application.properties文件内容是:

 

 

[plain]   
 
 
 
 
  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]   
 
 
 
 
  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,例如.jpa.properties..dialect,按“.”分割,都变成树状的配置

2,key后面的冒号,后面一定要跟一个空格

3,把原有的application.properties删掉。然后一定要执行一下  maven -X clean install

转载地址:http://uwael.baihongyu.com/

你可能感兴趣的文章
CSS之浮动那些事
查看>>
BPM实例方案分享:表单子表自动填入数据
查看>>
iproute(网卡限速)--使用方法
查看>>
开源项目spring-shiro-training思维导图
查看>>
Memcache 查看列出所有key的方法
查看>>
DataBinding初识
查看>>
CentOS Docker 安装
查看>>
python set(集合)
查看>>
(C#)把磁盘目录树加载在窗体菜单中
查看>>
centos6中三台物理机配置nginx+keepalived+lvs
查看>>
apache
查看>>
file_get_contents()采集不到原因
查看>>
FFmpeg常用基本命令
查看>>
Linux vmstat命令实战详解
查看>>
zip压缩工具、tar打包、打包并压缩
查看>>
PHP日期转星期(英文/数字)
查看>>
python 逻辑运算符
查看>>
Hibernate技术
查看>>
js实现限制输入框只能输入数字
查看>>
CentOS下杀毒工具ClamAV安装
查看>>