有些用过springBoot工程的人总有疑惑,springBoot工程中是有一个application.yml配置文件的啊,其实application.yml的功能和application.properties是一样的,不过因为yml文件是树状结构,写起来有更好的层次感,更易于理解,所以很多人都选择了yml文件。
下面来说说将工程改成application.yml配置文件的详细步骤
第一步:在application.properties 文件的同级目录下新建一个 application.yml 文件
![](https://img.haomeiwen.com/i8379736/01d3f55caf384066.png)
第二步:添加application.yml文件中的配置如下:
server:
port: 8088
spring:
datasource:
name: test
url: jdbc:mysql://localhost:3306/test
username: root
password: xxx
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
filters: stat
maxActive: 20
initialSize: 1
maxWait: 60000
minIdle: 1
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: select 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxOpenPreparedStatements: 20
如图所示:
![](https://img.haomeiwen.com/i8379736/2ce2b45456d6aafd.png)
第三步:删除原有的application.properties文件
文件结构如图示:
![](https://img.haomeiwen.com/i8379736/c75e223c86e30775.png)
第四步,重新编译maven工程
![](https://img.haomeiwen.com/i8379736/4789e36963d20bff.png)
找到maven工具栏,双击clean,待执行完成后,双击install,执行完成则编译成功。
第四步,重启springboot项目
![](https://img.haomeiwen.com/i8379736/a69a9ab58e681bce.png)
没有任何问题:
The End
网友评论