Maven packaged springboot projects in different environments

Maven packaged springboot projects in different environments

One, environment configuration

enter description here

2. Pom adds "repackage" packaged plug-in and "profiles" configuration

//添加插件
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
//添加profiles
 <profiles>
        <profile>
            <id>local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <spring.profiles.active>local</spring.profiles.active>
                <profileActive>local</profileActive>
            </properties>
        </profile>
        <profile>
            <id>dev</id>
            <properties>
                <spring.profiles.active>dev</spring.profiles.active>
                <profileActive>dev</profileActive>
            </properties>
        </profile>
        <profile>
            <id>pro</id>
            <properties>
                <spring.profiles.active>pro</spring.profiles.active>
                <profileActive>pro</profileActive>
            </properties>
        </profile>
    </profiles>

Three, application.yml configuration

spring:
  profiles:
    active: @profileActive@

Four, packaging

//默认local
mvn clean package
//dev环境
mvn clean package -P dev
//pro环境
mvn clean package -P pro

Guess you like

Origin blog.csdn.net/qq_39231769/article/details/109311606