基于maven的springboot的"過時"用法解析
序
接觸過許多工程,發(fā)現(xiàn)有一些基于maven的springboot工程還是使用maven的profile,有些"過時"了,下面簡單介紹一下。
示例1
pom.xml
<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>staging</id> <properties> <profiles.active>staging</profiles.active> </properties> </profile> <profile> <id>prod</id> <properties> <profiles.active>prod</profiles.active> </properties> </profile> </profiles> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <configuration> <target>1.8</target> </configuration> <executions> <execution> <id>copy-service-properties</id> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <copy todir="target/classes/config" overwrite="true"> <fileset dir="${basedir}/src/main/resources/deploy/${profiles.active}"> <include name="*.yml"/> </fileset> </copy> </tasks> </configuration> </execution> </executions> </plugin> </plugins> </build>
src/main/resources
├── config │?? ├── application.yml │?? └── bootstrap.yml ├── deploy │?? ├── Dockerfile │?? ├── dev │?? │?? ├── application.yml │?? │?? └── bootstrap.yml │?? ├── prod │?? │?? ├── application.yml │?? │?? └── bootstrap.yml │?? ├── staging │?? │?? ├── application.yml │?? │?? └── bootstrap.yml │?? └── test │?? ├── application.yml │?? └── bootstrap.yml
這種方法呢,感覺是多此一舉,用application-{profile}.yml不香嗎,感覺是沒有用上springboot之前的maven工程的用法
示例2
pom.xml
<profiles> <profile> <id>dev</id> <properties> <app.active>dev</app.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <app.active>test</app.active> </properties> </profile> <profile> <id>staging</id> <properties> <app.active>staging</app.active> </properties> </profile> <profile> <id>prod</id> <properties> <app.active>prod</app.active> </properties> </profile> </profiles>
application.yml
spring: profiles: active: @app.active@
這種用法呢,src/main/resources下面只有一個application.yml,把profile的差異放到了maven的profile中,在application.yml引用maven的profile變量,有點"少見多怪",直接application-{profile}.yml用不香嗎。
小結(jié)
springboot工程已經(jīng)提供了profile的特性了,其實大部分場景可以替換掉maven的profile,沒必要在使用maven的profile了,不然總感覺顯得有點古老和過時。
以上就是基于maven的springboot的"過時"用法的詳細內(nèi)容,更多關(guān)于maven的springboot的"過時"用法的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java使用ProcessBuilder?API優(yōu)化流程
Java?的?Process?API?為開發(fā)者提供了執(zhí)行操作系統(tǒng)命令的強大功能,這篇文章將詳細介紹如何使用?ProcessBuilder?API?來方便的操作系統(tǒng)命令,需要的可以收藏一下2023-06-06Spring?框架的?MethodInterceptor?簡介及示例代碼
MethodInterceptor接口定義了一個方法Object?intercept(Object?obj,?Method?method,?Object[]?args,?MethodProxy?proxy)?,該方法在代理對象的方法被調(diào)用時被觸發(fā),這篇文章主要介紹了Spring?框架的?MethodInterceptor?簡介及示例代碼,需要的朋友可以參考下2023-09-09Spring使用RestTemplate模擬form提交示例
本篇文章主要介紹了Spring使用RestTemplate模擬form提交示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03JavaFX程序初次運行創(chuàng)建數(shù)據(jù)庫并執(zhí)行建表SQL詳解
這篇文章主要介紹了JavaFX程序初次運行創(chuàng)建數(shù)據(jù)庫并執(zhí)行建表SQL詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2019-08-08在Java開發(fā)中無法繞開的SpringBoot框架詳解
SpringBoot是一個基于Spring框架的快速開發(fā)框架,它的出現(xiàn)極大地簡化了Spring應(yīng)用的開發(fā)流程,SpringBoot是一個快速開發(fā)的框架,它提供了一種快速構(gòu)建應(yīng)用程序的方式,本文給大家介紹在Java開發(fā)中無法繞開的框架:SpringBoot,感興趣的朋友一起看看吧2023-09-09使用IDEA創(chuàng)建maven父子工程項目 (圖文)
本文主要介紹了使用IDEA創(chuàng)建maven父子工程項目,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2022-04-04