在工作中,一个项目的诞生需要经历开发、测试、准生产、生产等多个步骤,在不同的步骤中我们使用的配置文件也可能存在不同,因此,我们需要对不同的环境配置相应的配置文件,并在主核心配置文件中选择我们当前要使用的配置文件。
自定义配置文件命名格式:"application-" + 自定义名 + ".properties"
【application-dev.properties】开发环境配置文件
# 开发环境配置文件
server.port=8080
server.servlet.context-path=/dev
【application-test.propertices】测试环境的配置文件
# 测试环境配置文件
server.port=8081
server.servlet.context-path=/test
【application-ready.propertices】准生产环境配置文件
# 准生产环境配置文件
server.port=8082
server.servlet.context-path=/ready
【application-product.propertices】生产环境配置文件
# 生产环境配置文件
server.port=8083
server.servlet.context-path=/product
【application.properties】主核心配置文件
在主核心配置文件中激活要使用的配置文件,只写 "-" 和 "." 之间的即可,如:dev、test、ready、product
# SpringBoot主核心配置文件
# 激活要使用的配置文件
spring.profiles.active=dev