簡體   English   中英

Google App Engine Standard Java 11 中的 Spring 啟動配置文件 - gcloud

[英]Spring boot profile in Google App Engine Standard Java 11 - gcloud

我正在通過 Github 操作部署我的 Spring Boot 應用程序。 我有使用 gcloud 執行應用程序部署的管道,以將我的應用程序部署到 Google App Engine 標准。 我已經創建了配置文件,我想在運行時將它注入到 Spring Boot 應用程序中

簡而言之:如何使用 gcloud 部署應用引擎標准 java 11 應用程序並支持 spring 配置文件

部署命令

app deploy src/main/appengine/app-dev.yaml --version=1

配置文件定義

<profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <ACTIVE_PROFILE>dev</ACTIVE_PROFILE>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <ACTIVE_PROFILE>prod</ACTIVE_PROFILE>
            </properties>
        </profile>
    </profiles>

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <profiles>
                        <profile>${ACTIVE_PROFILE}</profile>
                    </profiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.3.0</version>
                <configuration>
                    <projectId>${gcloud-projectId}</projectId>
                    <version>1</version>
                </configuration>
            </plugin>
        </plugins>
    </build>

app-dev.yaml 文件

 
runtime: java11
env: standard
instance_class: B4_1G
handlers:
  - url: .*
    script: auto
    secure: always
    redirect_http_response_code: 301
basic_scaling:
  max_instances: 5
  idle_timeout: 60m
env_variables:
  ACTIVE_PROFILE: dev

應用程序.yaml 文件

spring:
  profiles:
    active: @ACTIVE_PROFILE@

只需在 app.yaml 文件中包含 spring_profiles_active,我就可以在谷歌應用引擎標准 java 11 的 dev spring 配置文件中運行我的應用程序。

env_variables:
 spring_profiles_active: "dev"

這似乎是因為 App Engine 需要您的應用程序的入口點。

一些框架(包括 Spring Boot)構建了一個可執行的 uber JAR 文件。 發生這種情況時,運行時會通過運行 Uber JAR 應用程序來啟動您的應用程序。

因此,您需要一個 App Engine 將用於其內容的入口點。 這應該在您的app.yaml定義,如下所示:

runtime: java11
entrypoint: java -Xmx64m -jar YOUR-ARTIFACT.jar

其中示例YOUR-ARTIFACT.jar應用程序 jar 必須:

  • 與您的 app.yaml 文件位於根目錄中。
  • 在其 META-INF/MANIFEST.MF 元數據文件中包含 Main-Class 條目。
  • 或者,包含一個 Class-Path 條目,其中包含指向其他依賴 jar 的相對路徑列表。 這些將自動與應用程序一起上傳。

來源

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM