首页 > 解决方案 > 访问 Heroku 端点 - SpringBootApp 503Service 不可用

问题描述

我现在在 Heroku 中部署了一个 springBoot 应用程序,我想向这个应用程序发出一些请求,但我收到了 503 错误消息。

在我的本地,我使用下一个 url 来执行获取请求:http://localhost:8080/suggestions?q=Londo&latitude=43.70011&longitude=-79.4163

在 Heroku 中,我使用了下一个网址: https://heroku-boot-app-chall.herokuapp.com/suggestions?q=Londo&latitude=43.70011&longitude=-79.4163。我不太确定如何向部署在 Heroku 中的应用程序发出请求,构建成功。我只是在 github 和 Heroku 中提交我的资源我必须再做一步才能做一些请求?

这些是日志:

2020-03-15T22:41:18.739435+00:00 heroku[web.1]: State changed from crashed to starting
2020-03-15T22:41:24.686661+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=25003 $JAVA_OPTS -jar target/backend-coding-challenge-1.0-SNAPSHOT.jar`
2020-03-15T22:41:26.617949+00:00 heroku[web.1]: State changed from starting to crashed
2020-03-15T22:41:26.596700+00:00 heroku[web.1]: Process exited with status 1
2020-03-15T22:41:26.457261+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2020-03-15T22:41:26.469191+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2020-03-15T22:41:26.472555+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8 
2020-03-15T22:41:26.557238+00:00 app[web.1]: no main manifest attribute, in target/backend-coding-challenge-1.0-SNAPSHOT.jar
2020-03-15T22:46:51.520471+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/robots.txt" host=heroku-boot-app-chall.herokuapp.com request_id=5d91aac3-05d9-4075-83ce-1eea931f5a32 fwd="94.130.167.85" dyno= connect= service= status=503 bytes= protocol=https
2020-03-15T22:46:52.053784+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/suggestions?q=Londo&latitude=43.70011&longitude=-79.4163" host=heroku-boot-app-chall.herokuapp.com request_id=b9ba4950-1f83-4959-bc79-901a96d5fd02 fwd="94.130.167.85" dyno= connect= service= status=503 bytes= protocol=https

谢谢!

标签: javaspring-bootheroku

解决方案


最后,我必须使用以下信息创建一个 Procfile:

web: java -Dserver.port=$PORT -jar target/backend-coding-challenge-1.0-SNAPSHOT.jar

并将下一个插件添加到 pom.xml:

<build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <mainClass>com.heroku.CityAutocompleteService</mainClass>
        </configuration>

        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

推荐阅读