[英]configure maven profiles in spring boot @activeprofile annotation
我一直在閱讀很多,但找不到一個解決方案,告訴我如何在@activeprofiles注釋中包含maven配置文件。 有可能嗎?
我試圖在我的測試執行之前嘗試解決H2和flyway啟動的問題,這是沒有發生的。 配置在pom.xml中的maven配置文件中進行了解釋。 當測試在teamcity中運行時,它會選擇maven配置文件並執行但是作為獨立配置,他們無法找到H2和flyway的配置並且在啟動時失敗。
...無法找到一個解決方案,告訴我如何在@activeprofiles注釋中包含maven配置文件。
您是指基於maven配置文件激活Spring配置文件,如果是這樣,您可以在pom.xml中配置它:
<profiles>
<profile>
<id>mvnprofile</id>
<properties>
<spring.profiles.active>springprofile</spring.profiles.active>
</properties>
<dependencies>
<dependency>
</dependency>
</dependencies>
</profile>
...
</profiles>
在您的測試類中,配置它應運行的配置文件。
@Runwith(..)
@SpringApplicationConfiguration(...)
@ActiveProfiles("springprofile")
public class YourTest { ... }
對於輪廓特定屬性,創建一個application-springprofile.properties
除了你application.properties
,春天開機就會先加載application.properties然后加載application-springprofile.properties -覆蓋先前從application.properties配置的任何屬性。
最后,使用-P標志設置maven配置文件
$mvn test -P mvnprofile
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.