【发布时间】:2018-05-18 01:58:42
【问题描述】:
我正在尝试使用文档中指定的 72.1.1 Automatic property expansion using Maven,使用不同的 maven 配置文件,但 我无法使其与特定配置文件一起使用。
我有以下pom.xml:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<profiles>
<profile>
<id>local</id>
<activation>
<property>
<name>profileName</name>
<value>local</value>
</property>
</activation>
<properties>
<wildcard.for.customproperty>valueA</wildcard.for.customproperty>
</properties>
</profile>
<profile>
<id>external</id>
<activation>
<property>
<name>profileName</name>
<value>external</value>
</property>
</activation>
<properties>
<wildcard.for.customproperty>valueB</wildcard.for.customproperty>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.9.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
还有这个非常简单的application.properties:
custom.property=@wildcard.for.customproperty@
我使用 Spring Tool Suite 运行 maven 构建,目标如下:
clean install -DprofileName=local
构建成功,但目标文件夹中的application.properties 仍包含未解析的@...@ 占位符。
如果我在两个配置文件之一的 pom.xml 中添加这个简单的行:
<activeByDefault>true</activeByDefault>
占位符已正确解析。
这个配置有什么问题?
【问题讨论】:
-
不是用 -Pprofilename 激活了 maven 配置文件吗?
-
配置文件已正确激活,使用“help:active-profiles”目标和
功能进行检查。
标签: maven spring-boot-configuration spring-boot-starter