多环境开发配置,Spring boot
直接看代码, .yml 文件
# 公共属性 或 指定环境
spring:profiles:active: dev---
# 开发环境
spring:config:activate:on-profile: devdatasource:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://localhost:3306/newsusername: rootpassword: 123000data:redis:host: localhostport: 6379server:port: 8080mybatis:configuration:map-underscore-to-camel-case: true# 「---」 分割不同的环境
---# 测试环境
spring:config:activate:on-profile: testserver:port: 8085# 「---」 分割不同的环境
---# 生产环境
spring:config:activate:on-profile: runtimeserver:port: 9079
第一
spring:profiles:active: dev
当前环境是 —— dev 开发环境。
第二
spring:config:activate:on-profile: dev
配置开发环境的标识:
dev _ 开发环境
test _ 测试环境
runtime _ 生产环境
第三
# 「---」 分割不同的环境 ---
--- 用于分割不同的环境。
最后
# 公共属性 或 指定环境
spring:profiles:active: dev
server:servlet:context-path: /news
Tomcat started on port 8080 (http) with context path '/news'
这是多开发环境的单文件说明。
实际环境中,会是多文件配置。