当前位置: 首页 > 知识库问答 >
问题:

在Heroku上部署Spring Boot应用程序-构建成功,但随后:页面无法服务

巫经义
2023-03-14

当我用$java-jar demo-0.0.1-snapshot.jar在IntelliJ或cli中启动spring boot app/server时,它可以在本地工作,heroku构建也是成功的,但当我转到url时,它显示Application Error。有什么想法为什么heroku不显示我的网站吗?

我已经做了我在其他stackoverflow问题(Heroku不能部署Java11 Spring Boot App)中找到的提示:
1。我确保java版本是相同的:

在我的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.3.0.RELEASE</version>
             <relativePath/> <!-- lookup parent from repository -->
        </parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>

<properties>
    <java.version>11</java.version> <!-- =HERE is version 11 -->
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.junit.vintage</groupId>
                <artifactId>junit-vintage-engine</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>

        </plugin>

    </plugins>
</build>

</project>

我在根目录中创建了一个Procfile,其中包含以下内容:

Web:java-jar target/demo-0.0.1-snapshot.jar

我检查了SDK是否设置为11:

所有这些实际上都在我的git hub:https://github.com/gkromer/test2上,这里是我的应用程序的链接,来自heroku:https://nameless-chamber-03761.herokuapp.com/

我还在Heroku的入门页面上用简单的演示对其进行了测试。工作很好,没问题。因此,我认为问题出在我的IntelliJ或Maven上,因为我不需要heroku的示例(示例中的所有内容都可以通过CLI完成)。信息:我的spring应用程序中没有数据库。

当我跑的时候:

这是我的heroku日志尾巴:

$ heroku logs --tail
``2020-05-16T01:25:00.761021+00:00 app[web.1]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2020-05-16T01:25:00.761097+00:00 app[web.1]: \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2020-05-16T01:25:00.761171+00:00 app[web.1]: '  |____| .__|_| |_|_| |_\__, | / / / /
2020-05-16T01:25:00.761271+00:00 app[web.1]: =========|_|==============|___/=/_/_/_/
2020-05-16T01:25:00.762564+00:00 app[web.1]: :: Spring Boot ::        (v2.3.0.RELEASE)
2020-05-16T01:25:00.762662+00:00 app[web.1]:
2020-05-16T01:25:01.061558+00:00 app[web.1]: 2020-05-16 01:25:01.058  INFO 4 --- [               
main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on 
0e5ba3e8-29ec-44ea-b140-f4c7d9fbefe9 with PID 4 (/app/target/demo-0.0.1-SNAPSHOT.jar started 
by u23518 in /app)
2020-05-16T01:25:01.062689+00:00 app[web.1]: 2020-05-16 01:25:01.062  INFO 4 --- [           
main] com.example.demo.DemoApplication         : No active profile set, falling back to 
default profiles: default
2020-05-16T01:25:02.824876+00:00 app[web.1]: 2020-05-16 01:25:02.824  INFO 4 --- [            
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-05-16T01:25:02.847429+00:00 app[web.1]: 2020-05-16 01:25:02.847  INFO 4 --- [           
main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-05-16T01:25:02.847833+00:00 app[web.1]: 2020-05-16 01:25:02.847  INFO 4 --- [            
main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache 
Tomcat/9.0.35]
2020-05-16T01:25:02.940699+00:00 app[web.1]: 2020-05-16 01:25:02.940  INFO 4 --- [           
main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded 
WebApplicationContext
2020-05-16T01:25:02.940837+00:00 app[web.1]: 2020-05-16 01:25:02.940  INFO 4 --- [           
main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization 
completed in 1789 ms
2020-05-16T01:25:03.219257+00:00 app[web.1]: 2020-05-16 01:25:03.218  INFO 4 --- [           
main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService  
'applicationTaskExecutor'
2020-05-16T01:25:03.409097+00:00 app[web.1]: 2020-05-16 01:25:03.408  INFO 4 --- [           
main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: ServletContext resource 
[/index.html]
2020-05-16T01:25:03.579270+00:00 app[web.1]: 2020-05-16 01:25:03.578  INFO 4 --- [           
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with 
context path ''
2020-05-16T01:25:03.611887+00:00 app[web.1]: 2020-05-16 01:25:03.611  INFO 4 --- [           
main] com.example.demo.DemoApplication         : Started DemoApplication in 3.485 seconds 
(JVM running for 4.243)
2020-05-16T01:26:27.841081+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-16T07:01:26.964378+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-16T07:01:32.866428+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno 
size. Custom settings will override them.
2020-05-16T07:01:32.872188+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: 
-XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-16T07:01:34.924230+00:00 app[web.1]:
2020-05-16T07:01:34.924383+00:00 app[web.1]: .   ____          _            __ _ _
2020-05-16T07:01:34.924501+00:00 app[web.1]: /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2020-05-16T07:01:34.924566+00:00 app[web.1]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2020-05-16T07:01:34.924676+00:00 app[web.1]: \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2020-05-16T07:01:34.924759+00:00 app[web.1]: '  |____| .__|_| |_|_| |_\__, | / / / /
2020-05-16T07:01:34.924858+00:00 app[web.1]: =========|_|==============|___/=/_/_/_/
2020-05-16T07:01:34.926470+00:00 app[web.1]: :: Spring Boot ::        (v2.3.0.RELEASE)
2020-05-16T07:01:34.926515+00:00 app[web.1]:
2020-05-16T07:01:35.320062+00:00 app[web.1]: 2020-05-16 07:01:35.315  INFO 4 --- [           
main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on 
00e45ce7-7952-453c-a8f1-ed845e4c193e with PID 4 (/app/target/demo-0.0.1-SNAPSHOT.jar started 
by u31109 in /app)
2020-05-16T07:01:35.321331+00:00 app[web.1]: 2020-05-16 07:01:35.321  INFO 4 --- [           
main] com.example.demo.DemoApplication         : No active profile set, falling back to 
default profiles: default
2020-05-16T07:01:37.629271+00:00 app[web.1]: 2020-05-16 07:01:37.628  INFO 4 --- [           
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-05-16T07:01:37.676253+00:00 app[web.1]: 2020-05-16 07:01:37.675  INFO 4 --- [           
main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-05-16T07:01:37.676721+00:00 app[web.1]: 2020-05-16 07:01:37.676  INFO 4 --- [           
main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache 
Tomcat/9.0.35]
2020-05-16T07:01:37.821137+00:00 app[web.1]: 2020-05-16 07:01:37.820  INFO 4 --- [           
main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded 
WebApplicationContext
2020-05-16T07:01:37.821463+00:00 app[web.1]: 2020-05-16 07:01:37.821  INFO 4 --- [           
main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization  
completed in 2305 ms
2020-05-16T07:01:38.276493+00:00 app[web.1]: 2020-05-16 07:01:38.273  INFO 4 --- [           
main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 
'applicationTaskExecutor'
2020-05-16T07:01:38.454977+00:00 app[web.1]: 2020-05-16 07:01:38.454  INFO 4 --- [           
main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: ServletContext resource 
[/index.html]
2020-05-16T07:01:38.736300+00:00 app[web.1]: 2020-05-16 07:01:38.735  INFO 4 --- [           
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with 
context path ''
2020-05-16T07:01:38.759357+00:00 app[web.1]: 2020-05-16 07:01:38.759  INFO 4 --- [           
main] com.example.demo.DemoApplication         : Started DemoApplication in 4.771 seconds   
(JVM running for 5.887)
2020-05-16T07:03:01.250095+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-16T12:14:30.369161+00:00 heroku[router]: at=error code=H10 desc="App crashed" 
method=GET path="/" host=nameless-chamber-03761.herokuapp.com request_id=71365728-accd-48fa-
a5ed-d4f420b6cd3c fwd="77.181.100.181" dyno= connect= service= status=503 bytes= 
protocol=https
2020-05-16T12:14:30.742408+00:00 heroku[router]: at=error code=H10 desc="App crashed" 
method=GET path="/favicon.ico" host=nameless-chamber-03761.herokuapp.com 
request_id=24919523-0763-42f4-a9d2-8d148cdb97b8 fwd="77.181.100.181" dyno= connect= service= 
status=503 bytes= protocol=https
2020-05-16T12:16:03.537987+00:00 heroku[router]: at=error code=H10 desc="App crashed" 
method=GET path="/" host=nameless-chamber-03761.herokuapp.com request_id=5b7fb6ff-8868-4fc1-
b382-134f167bf327 fwd="77.181.100.181" dyno= connect= service= status=503 bytes= 
protocol=https
2020-05-16T12:28:00.000000+00:00 app[api]: Build started by user ****
2020-05-16T12:28:23.062523+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-16T12:28:22.893597+00:00 app[api]: Deploy 0e0889cc by user ****
2020-05-16T12:28:22.893597+00:00 app[api]: Release v4 created by user 
****
2020-05-16T12:28:27.000000+00:00 app[api]: Build succeeded
2020-05-16T12:28:29.021898+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno 
size. Custom settings will override them.
2020-05-16T12:28:29.029074+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: 
-XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-16T12:28:31.896036+00:00 app[web.1]:
2020-05-16T12:28:31.896107+00:00 app[web.1]: .   ____          _            __ _ _
2020-05-16T12:28:31.896138+00:00 app[web.1]: /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2020-05-16T12:28:31.896262+00:00 app[web.1]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2020-05-16T12:28:31.896402+00:00 app[web.1]: \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2020-05-16T12:28:31.896555+00:00 app[web.1]: '  |____| .__|_| |_|_| |_\__, | / / / /
2020-05-16T12:28:31.896661+00:00 app[web.1]: =========|_|==============|___/=/_/_/_/
2020-05-16T12:28:31.899913+00:00 app[web.1]: :: Spring Boot ::        (v2.3.0.RELEASE)
2020-05-16T12:28:31.899975+00:00 app[web.1]:
2020-05-16T12:28:32.281294+00:00 app[web.1]: 2020-05-16 12:28:32.276  INFO 4 --- [           
main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on 
5452f1b4-a278-48c5-98e1-c75bdd084232 with PID 4 (/app/target/demo-0.0.1-SNAPSHOT.jar started 
by u10860 in /app)
2020-05-16T12:28:32.284125+00:00 app[web.1]: 2020-05-16 12:28:32.283  INFO 4 --- [           
main] com.example.demo.DemoApplication         : No active profile set, falling back to 
default profiles: default
2020-05-16T12:28:34.522151+00:00 app[web.1]: 2020-05-16 12:28:34.521  INFO 4 --- [           
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
2020-05-16T12:28:34.554953+00:00 app[web.1]: 2020-05-16 12:28:34.554  INFO 4 --- [           
main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-05-16T12:28:34.555253+00:00 app[web.1]: 2020-05-16 12:28:34.555  INFO 4 --- [           
main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache  
Tomcat/9.0.35]
2020-05-16T12:28:34.675183+00:00 app[web.1]: 2020-05-16 12:28:34.674  INFO 4 --- [           
main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded  
WebApplicationContext
2020-05-16T12:28:34.675374+00:00 app[web.1]: 2020-05-16 12:28:34.675  INFO 4 --- [           
main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization  
completed in 2266 ms
2020-05-16T12:28:35.086773+00:00 app[web.1]: 2020-05-16 12:28:35.084  INFO 4 --- [           
main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 
'applicationTaskExecutor'
2020-05-16T12:28:35.242152+00:00 app[web.1]: 2020-05-16 12:28:35.241  INFO 4 --- [           
main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: ServletContext resource 
[/index.html]
2020-05-16T12:28:35.547679+00:00 app[web.1]: 2020-05-16 12:28:35.547  INFO 4 --- [           
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8090 (http) with 
context path ''
2020-05-16T12:28:35.599875+00:00 app[web.1]: 2020-05-16 12:28:35.599  INFO 4 --- [           
main] com.example.demo.DemoApplication         : Started DemoApplication in 4.748 seconds 
(JVM running for 6.57)
2020-05-16T12:29:57.002062+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-16T12:29:57.005306+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-16T12:30:02.809205+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno 
size. Custom settings will override them.
2020-05-16T12:30:02.814414+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: 
-XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2020-05-16T12:30:04.767929+00:00 app[web.1]:
2020-05-16T12:30:04.768123+00:00 app[web.1]: .   ____          _            __ _ _
2020-05-16T12:30:04.768241+00:00 app[web.1]: /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
2020-05-16T12:30:04.768352+00:00 app[web.1]: ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
2020-05-16T12:30:04.768464+00:00 app[web.1]: \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
2020-05-16T12:30:04.768619+00:00 app[web.1]: '  |____| .__|_| |_|_| |_\__, | / / / /
2020-05-16T12:30:04.768732+00:00 app[web.1]: =========|_|==============|___/=/_/_/_/
2020-05-16T12:30:04.770504+00:00 app[web.1]: :: Spring Boot ::        (v2.3.0.RELEASE)
2020-05-16T12:30:04.770574+00:00 app[web.1]:
2020-05-16T12:30:05.278180+00:00 app[web.1]: 2020-05-16 12:30:05.273  INFO 4 --- [           
main] com.example.demo.DemoApplication         : Starting DemoApplication v0.0.1-SNAPSHOT on 
39dcf1b4-d45d-48df-9410-0e6628be2d64 with PID 4 (/app/target/demo-0.0.1-SNAPSHOT.jar started 
by u20284 in /app)
2020-05-16T12:30:05.279551+00:00 app[web.1]: 2020-05-16 12:30:05.279  INFO 4 --- [           
main] com.example.demo.DemoApplication         : No active profile set, falling back to   
default profiles: default
 2020-05-16T12:30:05.652996+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" 
method=GET path="/" host=nameless-chamber-03761.herokuapp.com request_id=5bdbb8c6-a22f-446f-
ac6f-a1c6aec362f5 fwd="77.181.100.181" dyno= connect= service= status=503 bytes= 
protocol=https
2020-05-16T12:30:07.744043+00:00 app[web.1]: 2020-05-16 12:30:07.743  INFO 4 --- [           
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
2020-05-16T12:30:07.768880+00:00 app[web.1]: 2020-05-16 12:30:07.768  INFO 4 --- [           
main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-05-16T12:30:07.769379+00:00 app[web.1]: 2020-05-16 12:30:07.769  INFO 4 --- [           
main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache 
Tomcat/9.0.35]
2020-05-16T12:30:07.898340+00:00 app[web.1]: 2020-05-16 12:30:07.898  INFO 4 --- [           
main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded 
WebApplicationContext
2020-05-16T12:30:07.898510+00:00 app[web.1]: 2020-05-16 12:30:07.898  INFO 4 --- [           
main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization 
completed in 2476 ms
2020-05-16T12:30:08.282317+00:00 app[web.1]: 2020-05-16 12:30:08.281  INFO 4 --- [           
main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 
'applicationTaskExecutor'
2020-05-16T12:30:08.498359+00:00 app[web.1]: 2020-05-16 12:30:08.497  INFO 4 --- [           
main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: ServletContext resource 
[/index.html]
2020-05-16T12:30:08.728759+00:00 app[web.1]: 2020-05-16 12:30:08.728  INFO 4 --- [           
main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8090 (http) with 
context path ''
2020-05-16T12:30:08.759592+00:00 app[web.1]: 2020-05-16 12:30:08.759  INFO 4 --- [           
main] com.example.demo.DemoApplication         : Started DemoApplication in 4.84 seconds (JVM 
running for 5.945)
2020-05-16T12:31:05.938961+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" 
method=GET path="/" host=nameless-chamber-03761.herokuapp.com request_id=d5d37773-f24c-408f-
bc44-5db520817e47 fwd="77.181.100.181" dyno= connect= service= status=503 bytes= 
protocol=https
2020-05-16T12:31:30.779513+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-16T12:31:32.503518+00:00 heroku[router]: at=error code=H10 desc="App crashed" 
method=GET path="/" host=nameless-chamber-03761.herokuapp.com request_id=a8c93999-1d2c-4fe1-
ba38-520eeeaced15 fwd="77.181.100.181" dyno= connect= service= status=503 bytes= 
protocol=https

共有1个答案

华修永
2023-03-14

你就快到了,

Heroku dynos公开了一个动态端口供应用程序绑定。此值在$portenvvar中公开。

您可以在日志80808090...

web: java -Dserver.port=$PORT $JAVA_OPTS -jar target/demo-0.0.1-SNAPSHOT.jar
 类似资料:
  • 当我试图在heroku上部署springboot应用程序时,出现了以下错误: 无法执行目标org.apache.Maven.plugins:maven-compiler-plugin:3.8.1:在项目后端编译(default-compile):错误编译:无效的目标版本:11->[Help 1]Remote:[error]Remote:[error]要查看错误的全部堆栈跟踪,请使用-e开关重新运行

  • 我有一个spring-boot项目在IntelliJ IDE中运行良好,我试图将其部署在Heroku服务器上。该项目部署成功,但当我试图从POSTMAN访问它时,我得到了503错误:服务不可用。 以下是从Heroku成功部署后的日志记录: Heroku的申请日志: 有人能帮帮我吗?提前谢了。

  • 尝试在Heroku云中部署Spring Boot应用程序,但编译java应用程序时出现错误,但在我的本地计算机中运行良好。

  • 我的应用程序似乎总是在部署后崩溃。 2015-07-21T13:29:28.127452+00:00 Heroku[router]:at=error code=h10 desc=“应用程序崩溃”method=get path=“/api/v1/sessions”host=calm-hamlet-5165.herokuapp.com request_id=69711e3a-913e-45ed-b4b

  • 我在Openshift上运行node.js应用时遇到了问题。 我已经设置了我的 openshift 项目来从 git 存储库中提取。 我的< code>server.listen调用如下: 拉取和构建工作正常。我可以在pod终端中看到我的应用程序正在运行,因为有一些输出指示这一点。我还可以看到和都不存在,因此端口默认为。 如果我进入pod的终端并执行< code > curl http://loc

  • 编辑问题以包括所需的行为、特定问题或错误以及重现问题所需的最短代码。这将帮助其他人回答问题。 这是我第一个使用节点的代码,它在locahost:3000上运行良好。下面是我检查日志后的错误: