springboot使用profile完成對不同環境打包

日常對不同環境打包是需要更改application.properties文件。利用springboot-maven插件可以更加方便對不同環境打包。

application-dev.properties  開發環境

application-test.properties 測試環境

appliation-pro.properties 生成環境

要依賴插件當然得引入啦(這不是廢話麼)

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration> <!--設置程序執行的主類,一般來說就是帶SpringBootApplication註解的類 -->
        <mainClass>com.xxx.xxx.xx</mainClass>
        <fork>true</fork>
    </configuration>
</plugin>

然後就配置環境咯

<profiles>
    <!--開發環境-->
    <profile>
        <id>dev</id>
        <properties>
            <spring.profiles.active>dev</spring.profiles.active>
        </properties>
        <activation> <!-- 默認環境 -->
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <!--測試環境-->
    <profile>
        <id>test</id>
        <properties>
            <spring.profiles.active>test</spring.profiles.active>
        </properties>
    </profile>
    <!--生產環境-->
    <profile>
        <id>pro</id>
        <properties>
            <spring.profiles.active>pro</spring.profiles.active>
        </properties>
    </profile>
</profiles>

值得注意的是spring.profiles.active裏面的值要盒application-xxx對應上。

修改application.properties裏面的spring.profiles.active@spring.profiles.active@

這個時候你的idea就會出現一個神奇的東西。

沒錯,就是他。選中然後package就完成打包。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章