我已經看到了關于這個問題的所有問題和帖子,所以請不要將此標記為重復的問題或將我引向這些問題,我已經嘗試實施這些解決方案,但到目前為止沒有任何效果。
我有特定的profile.properties檔案,即 pom.xml application.properties 我正在進行 這是我在運行應用程式時得到的結果: 誰能在這里幫助我。 更新uj5u.com熱心網友回復: 你是否在你的 UpDATE
我已經把你的所有插件放到了一個樣本專案的 當我運行 我在日志檔案中看到 當我檢查 其中在原始碼 因此,如果你有一個類似于上述過濾的pom檔案,應該可以作業。
uj5u.com熱心網友回復: 非常感謝@pleft,我嘗試了所有的方法,正因為如此,我意識到這可能不是一個maven問題,而是一個IDE問題。我使用STS 3,我發現在 似乎已經有一個bug ticket來解決這個問題。
標籤:application-prod.properties, application-dev.properties, application-int.properties等<profiles>
<profile>/span>
<id>/span>prod</id>
<properties>/span>
<activeProfile>prod</activeProfile>
</properties>/span>
</profile>/span>
<profile>/span>
<id>/span>int</id>
<properties>/span>
<activeProfile>int</activeProfile>
</properties>/span>
</profile>/span>
<profile>/span>
<id>/span>dev</id>/span>
<properties>/span>
<activeProfile>/span>dev</activeProfile>
</properties>/span>
</profile>/span>
</profiles>/span>
<build>/span>
<resources>/span>
<resource>/span>
<directory>/span>src/main/resources</directory>
<filtering>true</filtering>
</resource>/span>
</resources>/span>
...
</build>
<plugins>/span>
<plugin>/span>
<groupId>/span>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>/span>
<archive>/span>
<index>true</index>
<manifest>/span>
<mainClass>com.demo.Application</mainClass>
</manifest>/span>
</archive>/span>
</configuration>/span>
</plugin>/span>
<plugin>/span>
<groupId>org.springframework.boot</groupId>/span>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>/span>
<plugin>/span>
<groupId>/span>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>/span>
<source>1.8</source>/span>
<target>1.8</target>/span>
</configuration>/span>
</plugin>/span>
<plugin>/span>
<groupId>/span>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<executions>/span>
<execution>>
<id>/span>show-profiles</id>/span>
<phase>compile</phase>
<目標>/span>
<goal>active-profiles</goal>
</goals>/span>
</執行>/span>
</executions>/span>
</plugin>/span>
</plugins>/span>
spring.profile.active=@activeProfile@
mvn clean install -Pprod,然后運行該應用程式。
我確信maven組態檔在構建程序中正在執行,因為我在構建程序中得到了這個結果以下組態檔處于活動狀態。
- prod (source: my-project-snapshot)
: 以下組態檔處于活動狀態。@activeProfile@
pom.xml中啟用了資源過濾功能?由于你使用的是spring-boot,所以可以很容易地啟用,在你的pom.xml<build>
<resources>/span>
<resource>/span>
<directory>/span>src/main/resources</directory>
<filtering>true</filtering>
</resource>/span>
</resources>/span>
...
</build>/span> ...
pom.xml中,也與你的spring-boot版本相匹配:<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven. apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"。
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"/span>>
<modelVersion>/span>4.0.0</modelVersion>/span>
<parent>/span>
<groupId>/span>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath/> <!--從版本庫中查找父本--> < >
</parent>
<groupId>in.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>/span>
<name>/span>demo</name>/span>
<description>Spring Boot的演示專案</description>
<properties>/span>
<java.version>11</java.version>/span>
</properties>/span>
<profiles>/span>
<profile>/span>
<id>/span>prod</id>
<properties>/span>
<activeProfile>prod</activeProfile>
</properties>/span>
</profile>/span>
<profile>/span>
<id>/span>dev</id>/span>
<properties>/span>
<activeProfile>/span>dev</activeProfile>
</properties>/span>
</profile>/span>
</profiles>/span>
<dependencies>>
<dependency>>
<groupId>/span>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>/span>
<dependency>>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>/span>
<dependency>>
<groupId>/span>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>/span>
<dependency>>
<groupId>/span>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>/span>
</dependencies>
<build>/span>
<resources>/span>
<resource>/span>
<directory>/span>src/main/resources</directory>
<filtering>true</filtering>
</resource>/span>
</resources>/span>
<plugins>/span>
<plugin>/span>
<groupId>org.springframework.boot</groupId>/span>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>/span>
<plugin>/span>
<groupId>/span>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<executions>/span>
<execution>>
<id>/span>show-profiles</id>/span>
<phase>compile</phase>
<目標>/span>
<goal>active-profiles</goal>
</goals>/span>
</執行>/span>
</executions>/span>
</plugin>/span>
<plugin>/span>
<groupId>/span>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>/span>
<source>1.8</source>/span>
<target>1.8</target>/span>
</configuration>/span>
</plugin>/span>
<plugin>/span>
<groupId>/span>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>/span>
<archive>/span>
<index>true</index>
<manifest>/span>
<mainClass>com.example.demo.DemoApplication</mainClass>
</manifest>
</archive>/span>
</configuration>/span>
</plugin>/span>
</plugins>/span>
</build>/span>
</project>
mvn clean package spring-boot:run -Pdev -DskipTests
com.example.demo.DemoApplication : 下列組態檔處于活動狀態:dev
target目錄下生成的jar時...targetdemo-0.0.1-SNAPSHOT.jarBOOT-INFclasses過濾已經成功,因為在application.properties中我得到一行:spring.profile.active=dev
application.properties中是spring.profile.active=@activeProfile@
Window > preferences > General > Workspace > Refresh using native hooks下禁用"Refresh using native hooks"可以解決STS IDE在STS打開時忽略-P<profile>問題。

