在POM中访问特定于Spring概要文件的应用程序属性

zero01alpha

我找不到任何可以解释如何在中访问特定于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

杰罗德·布罗泽(Gerold Broser)

请参阅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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用PropertiesLauncher启动的Spring-boot(特定于配置文件)应用程序中的问题覆盖应用程序属性

基于Spring的Web应用程序的特定于环境的配置?

Spring Boot应用程序中特定于环境的application.properties文件

访问特定于平台的应用程序数据区域

发送特定于应用程序的消息

在UWP应用程序包中包含特定于体系结构的文件

在Spring xml配置中访问SpEL中的应用程序属性

如何使纯文本文件应用程序特定于Spring云配置服务器?

如何从Firebase托管应用程序访问特定于环境的Firebase功能端点?

在Spring Boot 2.0 Web应用程序中,如何从静态Javascript文件中访问Java变量?

内部或外部存储,可编辑特定于应用程序的文件

是否可以通过媒体存储访问特定于应用程序的外部存储文件夹?

特定于应用程序的权限设置

Linux中的特定于应用程序的路由表

iOS中特定于应用程序的文件加密

无法在Spring Web应用程序中打开属性文件

Eclipse RCP:特定于应用程序的文件夹

我可以在tomcat 7中配置特定于应用程序的类路径目录吗?

在VS 2013 WP 8.1 Silverlight应用程序中访问文件属性时出现AcessViolationException

特定于应用程序的DNS问题?

特定于应用程序的映射

特定于应用程序的权限

Spring + Hibernate应用程序的特定于环境的配置

Twitter tweet / Facebook帖子或评论中的特定于应用程序的标志或属性

框架中的特定于应用程序的注入

在外部 tomcat 上作为 war 运行时,Spring Boot 应用程序不读取特定于环境的 yaml 文件

如何在我的 Flutter 应用程序中访问特定目录中的文件

从另一个应用程序访问特定于应用程序的数据

在 Laravel 中存储特定于应用程序的 conf 文件的最佳位置