在springboot项目中,有两种配置文件,一种是application.properties,另一种是application.yml,两种都可以配置spring boot 项目中的一些变量的定义,参数的设置等。下面来说说两者的区别:
用简单配置数据库为例:
application.properties如下所示:
spring.datasource.url=jdbc:mysql://localhost:3306/mxx?useUnicode=true&characterEncoding=utf8&useSSL=false spring.datasource.username=root spring.datasource.password=123456
application.yml如下所示:
spring: datasource: url: jdbc:mysql://localhost:3306/myblog?useUnicode=true&characterEncoding=utf8&useSSL=false username: root password: 123456
注意:使用.yml时,属性名的值和冒号中间必须有空格
一定注意文件格式,不然连接数据库失败。。。。会报错:我就是在applicaties配成yml格式。。。。
(Error querying database. Cause: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "EMP" not found; SQL statement:
SELECT eid,ename,dept,job,sal,phone,address FROM emp)
- application properties 数据库 数据 MySQLapplication properties数据库 数据 数据源application properties数据 application springboot properties就是 jdbctemplatedemo jdbctemplate application properties configurationproperties application properties application springboot properties文件 application properties sloans application树叶springboot properties application springboot properties sqlserver 全局application properties文件