java - appengine 中的配置文件激活 :deploy

标签 java maven google-app-engine

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

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

但它被忽略了。

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

最佳答案

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

1 - 创建 Maven 配置文件:

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

<!-- 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

关于java - appengine 中的配置文件激活 :deploy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53466360/

相关文章:

java - 由于缺少执行数据文件 :/var/lib/jenkins/workspace/soapuiauto1/hdap-project/tar‌​get/jacoco. exec 而跳过 JaCoCo 执行

java - ReSTLet 框架中基于表单的身份验证

java - Appengine 和 java.io 的使用

Java SimpleDateFormat ParseException 模式似乎匹配

java - 了解频繁更新的真实模型中的 EDT

java - 使用 Joda PersistentDateTime 保留提供的时区

Maven + Surefire 在失败的测试中返回代码为 0

java - 即使将库添加到 hadoop 文件夹后也找不到 BSONFileInputFormat

python - 在不知道 'compile' 时间的属性名称的情况下,在 Python 中复制 Google App Engine 数据存储中的实体

javascript - JSP : using java variable in Javascript