首页 > 解决方案 > Google AppEngine 上的 SpringBoot 无法找到或加载主类

问题描述

我使用 Spring Boot 创建了一个应用程序,并尝试将其部署到 Google AppEngine,但是当我的应用程序出现在日志中时,我看到了这条消息

Error: Could not find or load main class [MyMainClass]

这是app.yaml文件

runtime: java11
instance_class: F1
env: standard
entrypoint: java -cp "*" [MyMainClass] [ProjectName]-0.4.0.war

handlers:
  - url: /(.*\.(gif|png|jpg|js|css|env))$
    static_files: static/\1
    upload: static/.*\.(gif|png|jpg)$

这是appengine-web.xml文件

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <version>1</version>
    <threadsafe>true</threadsafe>
    <runtime>java11</runtime>
    <system-properties>
        <property name="java.util.logging.config.file" value="classes/logging.properties"/>
    </system-properties>
    <public-root>/src/main/webapp</public-root>
    <resource-files>
        <include path="/**.xml" />
        <exclude path="**/Icon\n" />
        <exclude path="**/Icon\n\r" />
        <exclude path="**/Icon\r" />
        <exclude path="**/Icon\r\n" />
    </resource-files>
</appengine-web-app>```


标签: spring-bootgoogle-app-enginedeployment

解决方案


我以这种方式修复:

  • 进入POM我将包设置为jar
...
<groupId>MyPackages</groupId>
<artifactId>MyProject</artifactId>
<version>MyVersion</version>
<packaging>jar</packaging>
...
  • 进入app.yaml我设置入口点
entrypoint: java -Xmx64m -jar target/[MyPackage.MyProject-MyVersion].jar

推荐阅读