SpringCloud 多环境配置

SpringCloud 多环境配置

项目顶层POM中增加如下配置

<!--  多环境配置  -->
    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profiles.active>dev</profiles.active>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profiles.active>test</profiles.active>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <profiles.active>prod</profiles.active>
            </properties>
        </profile>
    </profiles>

在项目层POM.xml 中增加以下配置

   <resources>
        <resource>
             <directory>src/main/resources</directory>
             <filtering>true</filtering>
         </resource>
 </resources>

在项目 的配置中增加 以下配置

spring:
  profiles:
    active: @profiles.active@

完整配置如下

spring:
  profiles:
    active: @profiles.active@
  application:
    name: wall-api
  cloud:
    nacos:
      discovery:
        group: wallServer
        namespace: wall-cloud-manager
        service: ${spring.application.name}
      config:
        group: wallServer
        namespace: wall-cloud-manager
        file-extension: yml
        prefix: ${spring.application.name}
---
# 开发环境
nacos:
  service:
    addr: 192.168.1.12:8848
spring:
  profiles: dev
  cloud:
    nacos:
      username: nacos
      password: nacos
      discovery:
        server-addr: ${nacos.service.addr}
      config:
        server-addr: ${nacos.service.addr}
---

idea打包方式

在这里插入图片描述

Maven 打包命令

mvn clean package -P dev

版权声明:本文为kisslongge00原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。