Open xuxiaowei-com-cn opened 1 year ago
mvn clean install
后,原来配置文件中是 application-@profiles.active@.yml
,打包后的产物是 application-dev.yml
参数 -Pxxx
修改配置了参数 -Pxxx
,也就是说,一个包可能只能在一个环境中使用,如果配置发生了变化,也只能通过重新打包来解决此问题(启动时,全部使用参数进行指定是不现实的做法)
xuxiaowei@DESKTOP-8E6LUNV MINGW64 /d/IdeaProjects-jihulab.com/mirrors-gitee/log4j/pig (jdk17-dev)
$ mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] pig [pom]
[INFO] pig-register [jar]
[INFO] pig-common [pom]
[INFO] pig-common-core [jar]
[INFO] pig-gateway [jar]
[INFO] pig-common-feign [jar]
[INFO] pig-common-mybatis [jar]
[INFO] pig-upms [pom]
[INFO] pig-upms-api [jar]
[INFO] pig-common-security [jar]
[INFO] pig-common-log [jar]
[INFO] pig-auth [jar]
[INFO] pig-common-oss [jar]
[INFO] pig-common-swagger [jar]
[INFO] pig-common-xss [jar]
[INFO] pig-upms-biz [jar]
[INFO] pig-common-bom [pom]
[INFO] pig-common-datasource [jar]
[INFO] pig-common-job [jar]
[INFO] pig-common-seata [jar]
[INFO] pig-visual [pom]
[INFO] pig-codegen [jar]
[INFO] pig-monitor [jar]
[INFO] pig-quartz [jar]
[INFO]
[INFO] -------------------------< com.pig4cloud:pig >--------------------------
[INFO] Building pig 3.7.1 [1/24]
******
[INFO] Reactor Summary for pig 3.7.1:
[INFO]
[INFO] pig ................................................ SUCCESS [ 0.442 s]
[INFO] pig-register ....................................... SUCCESS [ 13.649 s]
[INFO] pig-common ......................................... SUCCESS [ 0.030 s]
[INFO] pig-common-core .................................... SUCCESS [ 3.235 s]
[INFO] pig-gateway ........................................ SUCCESS [ 3.748 s]
[INFO] pig-common-feign ................................... SUCCESS [ 1.440 s]
[INFO] pig-common-mybatis ................................. SUCCESS [ 1.348 s]
[INFO] pig-upms ........................................... SUCCESS [ 0.025 s]
[INFO] pig-upms-api ....................................... SUCCESS [ 2.419 s]
[INFO] pig-common-security ................................ SUCCESS [ 2.406 s]
[INFO] pig-common-log ..................................... SUCCESS [ 1.427 s]
[INFO] pig-auth ........................................... SUCCESS [ 2.966 s]
[INFO] pig-common-bom ..................................... SUCCESS [ 0.022 s]
[INFO] pig-common-datasource .............................. SUCCESS [ 0.869 s]
[INFO] pig-common-job ..................................... SUCCESS [ 0.906 s]
[INFO] pig-common-seata ................................... SUCCESS [ 0.874 s]
[INFO] pig-visual ......................................... SUCCESS [ 0.021 s]
[INFO] pig-codegen ........................................ SUCCESS [ 3.004 s]
[INFO] pig-monitor ........................................ SUCCESS [ 1.229 s]
[INFO] pig-quartz ......................................... SUCCESS [ 2.619 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 50.726 s
[INFO] Finished at: 2023-09-01T10:15:41+08:00
[INFO] ------------------------------------------------------------------------
xuxiaowei@DESKTOP-8E6LUNV MINGW64 /d/IdeaProjects-jihulab.com/mirrors-gitee/log4j/pig (jdk17-dev)
$ cat pig-gateway/src/main/resources/application.yml
server:
port: 9999
spring:
application:
name: @artifactId@
cloud:
nacos:
username: @nacos.username@
password: @nacos.password@
discovery:
server-addr: ${NACOS_HOST:pig-register}:${NACOS_PORT:8848}
watch:
enabled: true
watch-delay: 1000
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
config:
import:
- optional:nacos:application-@profiles.active@.yml
- optional:nacos:${spring.application.name}-@profiles.active@.yml
xuxiaowei@DESKTOP-8E6LUNV MINGW64 /d/IdeaProjects-jihulab.com/mirrors-gitee/log4j/pig (jdk17-dev)
$ cat pig-gateway/target/classes/application.yml
server:
port: 9999
spring:
application:
name: pig-gateway
cloud:
nacos:
username: nacos
password: nacos
discovery:
server-addr: ${NACOS_HOST:pig-register}:${NACOS_PORT:8848}
watch:
enabled: true
watch-delay: 1000
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
config:
import:
- optional:nacos:application-dev.yml
- optional:nacos:${spring.application.name}-dev.yml
xuxiaowei@DESKTOP-8E6LUNV MINGW64 /d/IdeaProjects-jihulab.com/mirrors-gitee/log4j/pig (jdk17-dev)
$
测试环境已通过,正式环境需要重新打包,如何保证正式环境的打包产物与测试环境相同?
给 nacos 指定一个 namespace,从环境变量中去读取,就可以实现一份代码多端部署了吧。配置都放到了 nacos ,都是在 nacos 操作的。
给 nacos 指定一个 namespace,从环境变量中去读取,就可以实现一份代码多端部署了吧。配置都放到了 nacos ,都是在 nacos 操作的。
理想状态下,所有“打包产物中的配置”,都可以使用环境变量进行修改
pig-gateway,则可以配合:
spring.application.name=@artifactId@`spring.cloud.nacos.username=@nacos.username@
、spring.cloud.nacos.password=@nacos.password@
等等