【问题标题】:GAE - Class not found: Caused by: java.lang.ClassNotFoundExceptionAppIdentityCredential$AppEngineCredentialWrapperGAE - 找不到类:原因:java.lang.ClassNotFoundExceptionAppIdentityCredential$AppEngineCredentialWrapper
【发布时间】:2020-03-16 02:08:49
【问题描述】:

我正在尝试在 GAE 上启动一个简单的 Java (Maven) Spring Boot 应用程序,该应用程序与 PostrgreSql 服务器(也在云平台上)进行通信,但是我一直遇到缺少的依赖项。

我的 pom 中有这些依赖项:

    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter</artifactId>
      <version>1.1.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
      <version>1.1.3.RELEASE</version>
    </dependency>

但每当我将应用程序部署到 GAE 和 FlyWay 时,都会抛出以下问题:

java.lang.ClassNotFoundException: com.google.appengine.api.ThreadManager

我这里主要按照 Baeldung 教程:https://www.baeldung.com/spring-boot-google-app-engine

然后我找到了这个答案:AppEngine ClassNotFoundException: com.google.appengine.api.datastore.DatastoreServiceFactory 这导致我添加了 appengine 依赖项:

    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-api-1.0-sdk</artifactId>
      <version>1.9.77</version>
    </dependency>

然后抛出:

ClassNotFoundException: com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper

然后导致我添加客户端依赖项..等等..等等..

我的完整依赖集现在是:

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud</artifactId>
      <version>0.47.0-alpha</version>
    </dependency>
    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-api-1.0-sdk</artifactId>
      <version>1.9.77</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter</artifactId>
      <version>1.1.3.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
      <version>1.1.3.RELEASE</version>
    </dependency>

那..又回到了上面的异常:

ClassNotFoundException: com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential$AppEngineCredentialWrapper

所以这可能是一个依赖问题,但我找不到任何关于需要添加哪些依赖项才能让简单的 Spring Boot 应用程序运行到 PostgreSQL 服务器的文档。

我要认输了... 不过可能是睡眠不足

【问题讨论】:

    标签: java maven spring-boot google-app-engine spring-cloud-gcp


    【解决方案1】:

    您的 pom.xml 中缺少 App Engine 插件:

    <build>
      <plugins>
        <plugin>
          <groupId>com.google.cloud.tools</groupId>
          <artifactId>appengine-maven-plugin</artifactId>
          <version>1.3.2</version>
        </plugin>
      </plugins>
    </build>
    

    对于你得到的异常,我不知道你在哪里使用它,但你可以添加依赖:

    <dependency>
    <groupId>com.google.auth</groupId>
      <artifactId>google-auth-library-oauth2-http</artifactId>
      <version>0.18.0</version>
    </dependency>
    

    【讨论】:

    • 感谢您的回复;我已经试过了,没有用。 (appengine 已经在那里了)。我自己没有使用 oauth2,但是当我部署到 GAE 并访问生成的链接 (xxxx-something.appspot.com) 时,它会引发异常
    • 你能检查一下这个Github repo 并告诉我这是否对你有帮助。虽然,它是一个 Tomcat 应用程序,但我认为将其更改为 Spring App 并没有太多工作?这是一个将您的 Java App Engine 连接到 PostgreSQL 实例的简单应用程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 2019-12-29
    相关资源
    最近更新 更多