Heroku spring 应用程序构建成功但运行失败

时间:2021-03-10 03:00:24

标签: java spring spring-boot heroku

我已经使用 Spring 构建了一个 Web 应用程序,并且它在 localhost 中运行。当我使用以下日志将其部署到 heroku 时,构建成功

-----> Building on the Heroku-18 stack
-----> Java app detected
-----> Installing JDK 11... done
-----> Executing Maven
       $ ./mvnw -DskipTests clean dependency:list install
       [INFO] Scanning for projects...
       [INFO] 
       [INFO] -------------------------< sg.edu.iss:mytrial >-------------------------
       [INFO] Building mytrial 0.0.1-SNAPSHOT
       [INFO] --------------------------------[ jar ]---------------------------------
       [INFO] 
       [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ mytrial ---
       [INFO] 
       [INFO] --- maven-dependency-plugin:3.1.2:list (default-cli) @ mytrial ---
       [INFO] 
       [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ mytrial ---
       [INFO] Using 'UTF-8' encoding to copy filtered resources.
       [INFO] Using 'UTF-8' encoding to copy filtered properties files.
       [INFO] Copying 1 resource
       [INFO] Copying 27 resources
       [INFO] The encoding used to copy filtered properties files have not been set. This means that the same encoding will be used to copy filtered properties files as when copying other filtered resources. This might not be what you want! Run your build with --debug to see which files might be affected. Read more at https://maven.apache.org/plugins/maven-resources-plugin/examples/filtering-properties-files.html
       [INFO] 
       [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ mytrial ---
       [INFO] Changes detected - recompiling the module!
       [INFO] Compiling 57 source files to /tmp/build_901df98b/target/classes
       [INFO] /tmp/build_901df98b/src/main/java/sg/edu/iss/ca/controller/MyErrorController.java: /tmp/build_901df98b/src/main/java/sg/edu/iss/ca/controller/MyErrorController.java uses or overrides a deprecated API.
       [INFO] /tmp/build_901df98b/src/main/java/sg/edu/iss/ca/controller/MyErrorController.java: Recompile with -Xlint:deprecation for details.
       [INFO] 
       [INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ mytrial ---
       [INFO] Using 'UTF-8' encoding to copy filtered resources.
       [INFO] Using 'UTF-8' encoding to copy filtered properties files.
       [INFO] skip non existing resourceDirectory /tmp/build_901df98b/src/test/resources
       [INFO] 
       [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ mytrial ---
       [INFO] Changes detected - recompiling the module!
       [INFO] Compiling 8 source files to /tmp/build_901df98b/target/test-classes
       [INFO] 
       [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ mytrial ---
       [INFO] Tests are skipped.
       [INFO] 
       [INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ mytrial ---
       [INFO] Building jar: /tmp/build_901df98b/target/mytrial-0.0.1-SNAPSHOT.jar
       [INFO] 
       [INFO] --- spring-boot-maven-plugin:2.4.1:repackage (repackage) @ mytrial ---
       [INFO] Replacing main artifact with repackaged archive
       [INFO] 
       [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ mytrial ---
       [INFO] Installing /tmp/build_901df98b/target/mytrial-0.0.1-SNAPSHOT.jar to /tmp/codon/tmp/cache/.m2/repository/sg/edu/iss/mytrial/0.0.1-SNAPSHOT/mytrial-0.0.1-SNAPSHOT.jar
       [INFO] Installing /tmp/build_901df98b/pom.xml to /tmp/codon/tmp/cache/.m2/repository/sg/edu/iss/mytrial/0.0.1-SNAPSHOT/mytrial-0.0.1-SNAPSHOT.pom
       [INFO] ------------------------------------------------------------------------
       [INFO] BUILD SUCCESS
       [INFO] ------------------------------------------------------------------------
       [INFO] Total time:  11.243 s
       [INFO] Finished at: 2021-03-10T02:49:37Z
       [INFO] ------------------------------------------------------------------------
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 102.6M
-----> Launching...
       Released v30
       https://cims-spring.herokuapp.com/ deployed to Heroku

但是,当我尝试运行该应用程序时,我的 heroku 日志中显示以下错误:

2021-03-10T02:51:20.125315+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=cims-spring.herokuapp.com request_id=e3bf1cbe-0a85-46a6-91c5-e9be443b8724 fwd="220.255.55.225" dyno= connect= service= status=503 bytes= protocol=https
2021-03-10T02:51:20.565627+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=cims-spring.herokuapp.com request_id=540479be-1d1b-4504-b2b2-90605841225f fwd="220.255.55.225" dyno= connect= service= status=503 bytes= protocol=https

可以找到代码的存储库here

请帮忙,我已经尝试了我在谷歌上能找到的所有东西,但我没有想法

1 个答案:

答案 0 :(得分:-1)

Heroku 默认使用 OpenJDK 8 来运行您的应用程序,要更改版本,您必须向应用程序添加一个名为 system.properties 的文件。

在文件中设置一个属性 java.runtime.version:

  java.runtime.version=11

要了解更多信息,请点击此处https://devcenter.heroku.com/articles/java-support

如果可能,您可以将 Java 版本 11 更改为 8,这将更容易在默认情况下使用 Java 8 在 Heroku 上部署您的应用程序。