【问题标题】:Heroku 503 errorHeroku 503 错误
【发布时间】:2017-07-07 06:06:11
【问题描述】:

Heroku 在没有直接错误消息的情况下崩溃。这是日志:

2017-02-20T18:27:08.194304+00:00 app[web.1]: Hello World
2017-02-20T18:27:08.512366+00:00 heroku[web.1]: State changed from starting to crashed
2017-02-20T18:27:08.489335+00:00 heroku[web.1]: Process exited with status 0
2017-02-20T18:27:09.590397+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=x.herokuapp.com request_id=59533920-38d9-426f-a7e0-c32d667b8d49 fwd="94.187.7.67" dyno= connect= service= status=503 bytes=
2017-02-20T18:27:10.538493+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=x.herokuapp.com request_id=30fdd320-7ea6-4eb5-b3fa-8cf8c4240a21 fwd="94.187.7.67" dyno= connect= service= status=503 bytes=

heroku logs -n 1000 没有任何变化 这是我的代码:

public class Main {

public static void main(String[] args){
    System.out.println("Hello World");
  }

}

过程文件:

web: java -jar build/libs/app-name-1.0-SNAPSHOT.jar

Build.gradle:

version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.5

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
    }
}

repositories {
    mavenCentral()
}

task stage(dependsOn: ['build', 'clean'])
build.mustRunAfter clean

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

jar {
    manifest {
        attributes(
                'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
                'Main-Class': com.mypackage.Main
        )
    }
}
apply plugin: 'com.github.johnrengelman.shadow'

我可以看到正在打印Hello World。但是为什么之后会崩溃呢?

我正在使用带有 IntelliJ IDEA 的 Gradle

【问题讨论】:

  • 日志中应该有一个更具描述性的错误。你可以运行heroku logs -n 1000 并分享它吗?
  • @codefinger 我刚刚发现这个:错误:无法访问 jarfile build/libs/myAppName-1.0-SNAPSHOT-all.jar
  • @codefinger 嗯...不存在...
  • 运行 heroku run ls build/libs/ 以确认它在 Heroku 上
  • @codefinger 它不在 Heroku 上

标签: java heroku gradle


【解决方案1】:

这里的问题是应用程序不是网络应用程序。

考虑Procfile的内容:

web: java -jar build/libs/app-name-1.0-SNAPSHOT.jar

第一个词是web,它向 Heroku 建议您尝试部署一个 Web 应用程序。但根据其代码,该应用程序不是 Web 应用程序:

public class Main {

    public static void main(String[] args){
        System.out.println("Hello World");
    }

}

应用程序不会运行任何网络服务器,等待 80 或 8080 端口上的 HTTP 连接。应用程序只是将“Hello World”打印到标准输出并退出(因为到达程序末尾)。

2017-02-20T18:27:08.489335+00:00 heroku[web.1]: Process exited with status 0

Web 应用程序应该正在等待传入的连接。除非有人阻止它,否则它不能到达终点。

您可以使用this generator 生成Web 应用程序的模板。该应用程序将使用嵌入式 apache tomcat(将充当应用程序的 Web 服务器)和 spring-boot 来引导 Web 应用程序基础架构。 Here 是关于如何在 spring-boot 上编写 Hello World 应用程序的简短教程。它在 Heroku 上部署和工作。

【讨论】:

  • 天啊!我会尽可能奖励你的赏金
猜你喜欢
  • 2017-01-21
  • 2014-12-25
  • 2012-05-27
  • 2020-06-19
  • 2016-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-12
相关资源
最近更新 更多