当前位置: 首页 > 知识库问答 >
问题:

AppEngine中的配置文件激活:部署

田鸿彩
2023-03-14
mvn appengine:deploy -Dspring.profiles.active=prod

但却被忽略了。

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

共有1个答案

仲孙铭
2023-03-14

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

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

通过添加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>
<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> 
# Dev
mvn appengine:deploy -Pdev
# UAT
mvn appengine:deploy -Puat
#PROD
mvn appengine:deploy -Pprod
 类似资料:
  • Maven允许根据其运行的操作系统系列激活某些构建概要文件,例如: 这里有很多问题:那么的允许值是多少?它们区分大小写吗?Linux是吗?还是?等等。 我可以在哪里找到关于允许的值的信息-或者,至少,Maven从哪里获取这些值?环境变量?

  • 下面是我的Spring boot(2.4.5)应用程序的应用程序yaml,有两个配置文件。 Spring:配置文件:dev 但是根据环境配置文件可以不同。我不想硬编码配置文件

  • 我们有一个多模块maven项目,它有不同的平台可以运行,比如JBoss 4和JBoss 7。我们指定属性,然后将其用作工件的分类器,以及子模块中特定于平台的概要文件的激活,如: 在这些概要文件中,我们指定了提供的依赖项的版本。例如,我们进口jboss父pom: 因此,当我们将属性指定为命令行参数()时,它可以正常工作。 但是当属性在

  • 给定一个测试类,如: 我得到了错误: java.lang.IllegalStateException:配置错误:发现测试类[com.example.myControllerTest]的多个@BootStrapWith声明:[@org.springframework.test.context.bootStrapWith(value=class org.springframework.boot.tes

  • 我试图为dev、ct、e2e和prod创建Spring Boot配置文件。我正在使用application-*.yml文件来提供配置文件特定的设置。我能够成功激活ct和prod配置文件,但我不能激活开发和e2e配置文件。 我只在Intellij中观察到过这个问题。这是IntelliJ中的bug,还是我遗漏了什么?

  • null 我找到的消息来源,但没有解决我的问题: http://www.baeldung.com/cucumber-spring-integration(使用@ContextConfiguration loader和SpringApplicationContextLoader.class(在撰写本文时的最新版本Spring Boot1.5.2中没有)。 在Cucumber中编程设置Spring配置