基于maven的springboot的"過(guò)時(shí)"用法解析
序
接觸過(guò)許多工程,發(fā)現(xiàn)有一些基于maven的springboot工程還是使用maven的profile,有些"過(guò)時(shí)"了,下面簡(jiǎn)單介紹一下。
示例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
這種方法呢,感覺(jué)是多此一舉,用application-{profile}.yml不香嗎,感覺(jué)是沒(méi)有用上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下面只有一個(gè)application.yml,把profile的差異放到了maven的profile中,在application.yml引用maven的profile變量,有點(diǎn)"少見(jiàn)多怪",直接application-{profile}.yml用不香嗎。
小結(jié)
springboot工程已經(jīng)提供了profile的特性了,其實(shí)大部分場(chǎng)景可以替換掉maven的profile,沒(méi)必要在使用maven的profile了,不然總感覺(jué)顯得有點(diǎn)古老和過(guò)時(shí)。
以上就是基于maven的springboot的"過(guò)時(shí)"用法的詳細(xì)內(nèi)容,更多關(guān)于maven的springboot的"過(guò)時(shí)"用法的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Java編寫(xiě)日志手機(jī)號(hào)脫敏工具類(lèi)
在開(kāi)發(fā)過(guò)程中,很容易將用戶敏感信息,例如手機(jī)號(hào)碼、身份證等,打印在日志平臺(tái),本文將利用Java編寫(xiě)一個(gè)日志手機(jī)號(hào)脫敏工具類(lèi),感興趣的可以了解下2024-12-12Java使用ProcessBuilder?API優(yōu)化流程
Java?的?Process?API?為開(kāi)發(fā)者提供了執(zhí)行操作系統(tǒng)命令的強(qiáng)大功能,這篇文章將詳細(xì)介紹如何使用?ProcessBuilder?API?來(lái)方便的操作系統(tǒng)命令,需要的可以收藏一下2023-06-06Spring?框架的?MethodInterceptor?簡(jiǎn)介及示例代碼
MethodInterceptor接口定義了一個(gè)方法Object?intercept(Object?obj,?Method?method,?Object[]?args,?MethodProxy?proxy)?,該方法在代理對(duì)象的方法被調(diào)用時(shí)被觸發(fā),這篇文章主要介紹了Spring?框架的?MethodInterceptor?簡(jiǎn)介及示例代碼,需要的朋友可以參考下2023-09-09Spring使用RestTemplate模擬form提交示例
本篇文章主要介紹了Spring使用RestTemplate模擬form提交示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03JavaFX程序初次運(yùn)行創(chuàng)建數(shù)據(jù)庫(kù)并執(zhí)行建表SQL詳解
這篇文章主要介紹了JavaFX程序初次運(yùn)行創(chuàng)建數(shù)據(jù)庫(kù)并執(zhí)行建表SQL詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08在Java開(kāi)發(fā)中無(wú)法繞開(kāi)的SpringBoot框架詳解
SpringBoot是一個(gè)基于Spring框架的快速開(kāi)發(fā)框架,它的出現(xiàn)極大地簡(jiǎn)化了Spring應(yīng)用的開(kāi)發(fā)流程,SpringBoot是一個(gè)快速開(kāi)發(fā)的框架,它提供了一種快速構(gòu)建應(yīng)用程序的方式,本文給大家介紹在Java開(kāi)發(fā)中無(wú)法繞開(kāi)的框架:SpringBoot,感興趣的朋友一起看看吧2023-09-09使用IDEA創(chuàng)建maven父子工程項(xiàng)目 (圖文)
本文主要介紹了使用IDEA創(chuàng)建maven父子工程項(xiàng)目,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04