我找不到任何可以解释如何在中访问特定于Spring Profile的应用程序属性的内容pom.xml
。这可能吗?我发现了很多有关执行相反操作的信息(访问应用程序中的Maven配置文件属性),但与此无关。
我的特定用例是能够从如下所示的属性文件中在Tomcat插件中设置Tomcat管理器URL。请记住,我的问题只是标题中的内容,我并没有寻求帮助来配置Tomcat插件,因此我不会在问题标签中包含它。
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>${tomcat.manager.url}</url>
<server>${tomcat.server.name}</server>
</configuration>
</plugin>
我的POM中有以下配置文件:
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<activatedProperties>test</activatedProperties>
</properties>
</profile>
</profiles>
而这在相同的POM的build元素中:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
在我的application.properties
:
# active profile placeholder for the active maven profile. Defaults to dev.
spring.profiles.active=@activatedProperties@
在我的application-test.properties
:
tomcat.manager.url=http://mydomain:8080/manager/text
tomcat.server.name=myserver
但是当我运行
mvn tomcat7:redeploy -DskipTests -P test
它不会尝试部署到http://mydomain:8080/manager/text
,而是使用默认值localhost:8080
。
请参阅Properties Maven插件的read-project-properties
目标:
read-project-properties目标读取属性文件和URL,并将属性存储为项目属性。
因此,将以下内容添加到您的POM中:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${project.basedir}/src/main/resouces/application-test.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句