创建好SpringBoot项目后,框架自带的是properties文件,这里使用yml文件进行配置,所以将application.properties改为application.yml文件,并进行相关配置。 我们在开发项目的时候,一般开发环境和部署环境会不一样,为了加以区分,可以在yml配置文件中体现出来,所以分为application-dev.yml(开发环境)、application-pro.yml(部署环境),而为了能够让SpringBoot知道用的是哪个配置文件,需要在application.yml配置文件中加以说明,并且开发和部署中相同的配置也可以在application.yml中进行配置,详细配置如下:
-
application.yml:公共配置和表明当前配置文件
-
application-dev.yml:开发环境配置文件
-
application-pro.yml:部署环境配置文件
application.yml
spring:
thymeleaf:
mode: HTML
profiles:
active: pro
mybatis:
type-aliases-package: com.star.entity
mapper-locations: classpath:mapper/*.xml
configuration:
map-underscore-to-camel-case: true
application-dev.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/myblog?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
username: root
password: 111111
logging:
level:
root: info
com.star: debug
file: log/blog-dev.log
application-pro.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/myblog?useUnicode=true&characterEncoding=utf-8&useSSL=false&server
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
Timezone=UTC&serverTimezone=GMT%2B8
username: root
password: 111111
logging:
level:
root: warn
com.star: info
file: log/blog-pro.log<