我在我的 maven pom 中得到了以下組態檔:
<profiles>
<profile>
<id>local</id>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<profiles>
<profile>local</profile>
</profiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
這對于啟動應用程式很好,但是如果我想按照以下方式構建應用程式,
mvn clean install -Plocal
我的@SpringBootTest
失敗是由于:
No active profile set, falling back to default profiles: default
也試過:
<profile>
<id>local</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<argLine>-Dspring.profiles.active=local</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
我錯過了什么?
psmvn spring-boot:run -Plocal
在那里作業沒問題......也沒有興趣
mvn clean install -Dspring.profiles.active=local
我知道這有效但只是不感興趣,因為組態檔不僅僅包含我們的組態檔!
uj5u.com熱心網友回復:
(你的)Spring-boot-maven-plugin(配置)不受“安裝”目標的影響(它只涉及 spring-boot:repackage,它不知道“活動組態檔”/這個配置),這就是為什么你的組態檔(雖然傳播)未在您的測驗中激活。
如果您希望它為 作業mvn install
,則必須通過:
-Dspring.profiles.active=local
到:
萬無一失的插件
在 pom(>profile>build>plugins) 中:
<plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <argLine>-Dspring.profiles.active=local</argLine> </configuration> </plugin>
或通過 cmd。也可以看看。 插件檔案。
故障安全插件...類似!;) Plugin-Doc。
也許更多......(任何其他插件,啟動spring-boot。)
但是當然,請不要“忘記” about
@ActiveProfiles
,它會激活(更準確地說是添加!)組態檔到您的測驗(類)。(但建立獨立;)并且(當然;)您還可以
spring.profiles.active
在您的應用程式(屬性/任何位置)中的某處“打包” ,(幾乎)任何“maven 構建”。例如:
pom.xml:
<profile> <id>local</id> <properties> <myProfiles>local,foo,bar</myProfiles> </properties> </profile> <!-- ... and (outside/in default profile!) --> <build> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> </testResources> <!-- ... --> </build>
src/test/resources/application.properties:
spring.profiles.active=${myProfiles}
將寫入 target/test-classes/application.properties:
spring.profiles.active=local,foo,bar
...,這將(希望)被“下一個測驗”接收并激活。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/359801.html