1. 在pom.xml文件中配置
<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <activatedProperties>dev</activatedProperties>
        </properties>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <activatedProperties>test</activatedProperties>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <activatedProperties>prod</activatedProperties>
        </properties>
    </profile>
</profiles>
配置finalName打包后文件名中包含环境信息
<build>
    <finalName>springboot-demo-${activatedProperties}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
2. 在application.properties中配置当前激活的环境
spring.profiles.active=@activatedProperties@
3. 使用 mvn 命令进行打包
mvn clean package -P dev
mvn clean package -P test
mvn clean package -P prod
在 eclipse 中配置

4. 使用 java -jar 命令选择不同环境启动
java -jar project-demo.jar --spring.profiles.active=prod
# 后台启动方式
nohup java -jar project-demo.jar --spring.profiles.active=prod > /dev/null 2>&1 &
 
  
  
 