簡體   English   中英

使用 java11 在谷歌雲上使用 mysql 部署 Spring 啟動應用程序

[英]Deploying a Spring boot application with mysql on google cloud with java11

在 Google Cloud 上配置 mysql 后,我嘗試使用 Google App Engine Deployment 進行部署。 在本地主機上它運行得很好,但是當我嘗試在服務器上運行時它有一些問題。 我找到了降低 java 版本的解決方案,但我需要 java 11,是否有任何解決方案可以使用 java 11 部署我的應用程序?

錯誤:

File upload done.
ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: Frontend automatic scaling should NOT have the following parameter(s): [max_total_instances, min_total_instances] (or "version.env" should be set to "flex"
- '@type': type.googleapis.com/google.rpc.BadRequest
  fieldViolations:
  - description: 'Frontend automatic scaling should NOT have the following parameter(s):
      [max_total_instances, min_total_instances] (or "version.env" should be set to
      "flex"'
    field: version.automatic_scaling
Failed to deploy '[2021-11-10 23:11:21] Maven build: backend. Project: buildtogether. Version: auto': Deployment failed with exit code: 1
Please make sure that you are using the latest version of the Google Cloud SDK.
Run ''gcloud components update'' to update the SDK. (See: https://cloud.google.com/sdk/gcloud/reference/components/update.)

我的 pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.6</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ubul_studio</groupId>
    <artifactId>build_together</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>build_together</name>
    <description>Backend for the Build Together mobile and webapp</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <!-- Add Spring Cloud GCP Dependency BOM -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.google.cloud</groupId>
                <artifactId>spring-cloud-gcp-dependencies</artifactId>
                <version>2.0.5</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>com.neovisionaries</groupId>
            <artifactId>nv-i18n</artifactId>
            <version>1.22</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.4.0</version>
                <configuration>
                    <version>1</version>
                    <projectId>buildtogether</projectId>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我的 app.yaml:

runtime: java11

instance_class: F2
env_variables:
  BUCKET_NAME: "example-gcs-bucket"

handlers:
  - url: /stylesheets
    static_dir: stylesheets

  - url: /.*
    secure: always
    redirect_http_response_code: 301
    script: auto

automatic_scaling:
  min_num_instances: 1
  max_num_instances: 8

我的應用程序.yml:

spring:
  cloud:
    gcp:
      sql:
        database-name: buildtogether
        instance-connection-name: buildtogether:europe-central2:buildtogether
  datasource:
    password: buildtogether
    username: root
    url: jdbc:mysql://34.116.151.33:3306/buildtogether

  profiles:
    active: mysql

  jpa:
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        dialect: org.hibernate.dialect.MySQL57InnoDBDialect


  liquibase:
    change-log: classpath:database/db.changelog-master.xml
    default-schema: buildtogether
  sql:
    init:
      mode: always

請參閱app.yml的文檔。 我相信您應該指定min_instancesmax_instances ,而不是min_num_instancesmax_num_instances

min_num_instancesmax_num_instances適用於 python 運行時。

轉換 ArrayList 列表的最佳方法是什么<object>到自定義 object java11 Spring 引導 2.1<div id="text_translate"><p> 我有 ArrayList 對象列表,其中對象可以是文本、BigDecimal、Long</p><pre> List&lt;Object&gt; data = { {"date","prize1","cardsNumers","cardObtained","totalCards","anotherPrize"}, {"2020-05-01",435345.67,43,56,67,345345345}, {"2020-03-01",45656.2,34,67,23,456456}, {"2020-02-01",56565,34,56,67,878987} }</pre><p> arrayList 中的第 1、2、3 等對象是第 0 個 arraylist 中提到的每個字段的值。 在如下表中,</p><p> <a href="https://i.stack.imgur.com/Tmdw2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tmdw2.png" alt="在此處輸入圖像描述"></a></p><p> 我想從上面獲取每個文件的總和並分配給下面自定義 Object 的同一字段,</p><pre> public class SumObject { private Date date; private BigDecimal sumPrize1; private BigDecimal sumCardsNumers; private long sumCardObtained; private long sumTotalCards; private long sumAnotherPrize; }</pre><p> 我通過遍歷 List 中的 arrayList 來實現這一點,並通過 get(index) 方法獲取值。 但我想知道是否有任何其他好的方法可以做到這一點。</p><p> 如果有人有任何建議,請發布答案或給我一個我可以閱讀的文件的方向。</p><p> 提前致謝。</p></div></object>

[英]what would be best way to convert List of ArrayList<Object> to a custom object java11 Spring boot 2.1

暫無
暫無

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

相關問題 Java-11 spring-boot 部署到谷歌雲錯誤:應用程序不滿足 [java11] 的要求 Spring boot App使用Google雲Mysql部署到Heroku 使用 java11 在 Google App Engine 上部署單個 jar 時防止構建嘗試 Google Cloud Dataflow 使用什么 java 運行時? java8 或 java11 無法在雲上部署Spring Boot應用程序 轉換 ArrayList 列表的最佳方法是什么<object>到自定義 object java11 Spring 引導 2.1<div id="text_translate"><p> 我有 ArrayList 對象列表,其中對象可以是文本、BigDecimal、Long</p><pre> List&lt;Object&gt; data = { {"date","prize1","cardsNumers","cardObtained","totalCards","anotherPrize"}, {"2020-05-01",435345.67,43,56,67,345345345}, {"2020-03-01",45656.2,34,67,23,456456}, {"2020-02-01",56565,34,56,67,878987} }</pre><p> arrayList 中的第 1、2、3 等對象是第 0 個 arraylist 中提到的每個字段的值。 在如下表中,</p><p> <a href="https://i.stack.imgur.com/Tmdw2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tmdw2.png" alt="在此處輸入圖像描述"></a></p><p> 我想從上面獲取每個文件的總和並分配給下面自定義 Object 的同一字段,</p><pre> public class SumObject { private Date date; private BigDecimal sumPrize1; private BigDecimal sumCardsNumers; private long sumCardObtained; private long sumTotalCards; private long sumAnotherPrize; }</pre><p> 我通過遍歷 List 中的 arrayList 來實現這一點,並通過 get(index) 方法獲取值。 但我想知道是否有任何其他好的方法可以做到這一點。</p><p> 如果有人有任何建議,請發布答案或給我一個我可以閱讀的文件的方向。</p><p> 提前致謝。</p></div></object> 從 java spring boot 應用程序調用谷歌雲函數 在雲中使用Maven和MySQL部署Spring Web應用程序? 遷移到Java11 Google Cloud Platform - Cloud SQL 上 MySQL 的 Spring Boot 應用程序連接問題
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM