开发环境与生产环境的 yml 文件与配置
Spring boot 的 maven 打包过程-CSDN博客
Spring boot 打包后,部署后 yml 文件的配置:
开发环境配置 application-dev.yml
bizbaijing:datasource:driver-class-name: com.mysql.cj.jdbc.Driverhost: localhostport: 3306database: sky_take_outusername: rootpassword: 12357896redis:host: localhostport: 6379database: 0aliyun:oss:endpoint: https://oss-cn-beijing.aliyuncs.combucket-name: bizbaijingregion: cn-beijing
具体的值,放到这个文件中。
生产环境,在配置生产环境的 yml 文件
application-runtime.yml
application.yml 的内容
spring:profiles:active: devmain:allow-circular-references: truedatasource:druid:driver-class-name: ${bizbaijing.datasource.driver-class-name}url: jdbc:mysql://${bizbaijing.datasource.host}:${bizbaijing.datasource.port}/${bizbaijing.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=trueusername: ${bizbaijing.datasource.username}password: ${bizbaijing.datasource.password}mysql:usePingMethod: falseredis:host: ${bizbaijing.redis.host}port: ${bizbaijing.redis.port}database: ${bizbaijing.redis.database}
写成配置变量,在不同的环境切换不同的具体值。