【问题标题】:Profile activation in appengine:deployappengine:deploy 中的配置文件激活
【发布时间】:2019-04-27 05:27:24
【问题描述】:

我正在尝试使用 maven 命令激活 AppEngine 应用程序的配置文件,如下所示:

mvn appengine:deploy -Dspring.profiles.active=prod

但它被忽略了。

是否可以使用 maven 激活配置文件?

【问题讨论】:

  • 您是否将配置文件添加到 POM 中?可以显示吗?
  • @user7294900 我正在处理弹簧配置文件而不是 maven 配置文件,所以我在 POM 中没有配置文件。但即使我使用 Maven 配置文件,我也会遇到同样的问题?
  • 我已经试过了。问题是 mvn appengine:deploy 似乎 GCP 中的部署版本忽略了 maven 命令中指定的每个选项
  • 我使用 appengine-web.xml 文件解决了这个问题

标签: java maven google-app-engine


【解决方案1】:

我成功地将 Maven 配置文件链接到 Spring 配置文件。下面我解释一下我是怎么做的:

1 - 创建 Maven 配置文件:

pom.xml 中,我确定了我的 maven 配置文件,稍后会将它们链接到 spring 配置文件,方法是将它们存储在“spring.profiles.to.activate”属性中:

<!-- PROFILES -->
<profiles>
    <profile>
        <id>dev</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <properties>
            <spring.profiles.to.active>dev</spring.profiles.to.active>
        </properties>
    </profile>
    <profile>
        <id>uat</id>
        <properties>
            <spring.profiles.to.active>uat</spring.profiles.to.active>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <spring.profiles.to.active>prod</spring.profiles.to.active>
        </properties>
    </profile>
</profiles> 

2 - 激活 Maven 过滤:

我通过添加 maven-war-plugin 来构建文件夹 ${basedir}/src/main/webapp 中的过滤功能。 这将允许我们在提到的文件夹中解析占位符 ${...}(在这种特殊情况下为 ${spring.profiles.to.activate})。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resources>
                <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                <filtering>true</filtering>
                <targetPath>WEB-INF</targetPath>
            </resources>
        </webResources>
    </configuration>
</plugin>

3- 激活配置文件 Spring

appengine-web.xml 中声明系统属性:“spring.profiles.active”作为 maven 属性 ${spring.profiles.to.activate}

<appengine-web-app
    xmlns="http://appengine.google.com/ns/1.0">
    <version>1</version>
    <threadsafe>true</threadsafe>
    <runtime>java8</runtime>
    <system-properties>
        <property name="spring.profiles.active" value="${spring.profiles.to.active}" />
    </system-properties>
</appengine-web-app> 

4 - 部署到 Appengine

# Dev
mvn appengine:deploy -Pdev
# UAT
mvn appengine:deploy -Puat
#PROD
mvn appengine:deploy -Pprod

【讨论】:

    【解决方案2】:
    #dev profile, try adding space between -P and dev
    mvn appengine:deploy  -P dev   
    #uat profile, try adding space between -P and uat
    mvn appengine:deploy  -P qa
    #prod profile, try adding space between -P and prod
    mvn appengine:deploy  -P prd
    

    【讨论】:

      猜你喜欢
      • 2011-11-12
      • 2014-10-29
      • 2011-07-17
      • 2016-05-20
      • 1970-01-01
      • 2019-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多