一、背景
由于项目中加了bootstrap.properties文件,且文件中有变量,如spring.cloud.config.profile=${spring.profiles.active},而bootstrap.properties读取的优先级高于application.properties,所以参数不能配置在application.properties中,以下记录几种配置方式
二、方式一:通过java程序启动命令行参数设置
这种一般线上会这么做,即打docker镜像或者虚拟机上运行的时候,如下所示:
设置-Dspring.profiles.active=pro:
- docker:
-
- CMD ["java","-server","-Dfastjson.parser.safeMode=true","-XX:+UseG1GC","-XX:InitialRAMPercentage=40.0","-XX:MinRAMPercentage=20.0","-XX:MaxRAMPercentage=75.0","-XX:MaxHeapFreeRatio=40","-XX:+DisableExplicitGC","-Dspring.profiles.active=pro","-jar","hubbleservicename-hubbleserviceversion-SNAPSHOT.jar","-Dfile.encoding=utf-8"]
三、方式二:IDEA启动配置