Skip to content
Advertisement

Heroku SprinBoot Deployment is sucess but Status is 503 Service Unavailable

Hi I am trying to deploy a Spring Boot Application to Heroku. The build is a success but when I try to run the app I get a Status 503: Service Unavailable Error.

I referred a similar post Application Error after a successful deployment at Heroku but this didn’t helped me.

Here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>

4.0.0 org.springframework.boot spring-boot-starter-parent 2.5.2 com.sample.app sample-app 0.0.1-SNAPSHOT sample-app Sample Project <java.version>11</java.version> jar org.springframework.boot spring-boot-starter-data-jdbc org.springframework.boot spring-boot-starter-web

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.networknt</groupId>
        <artifactId>json-schema-validator</artifactId>
        <version>1.0.57</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>11</source>
                <target>11</target>
            </configuration>
        </plugin>
    </plugins>
</build>

Here is the error log from heroku logs --tail

Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2021-09-02T07:19:39.158915+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-09-02T07:19:39.162760+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-09-02T07:19:39.289159+00:00 app[web.1]: no main manifest attribute, in target/XXX.jar
2021-09-02T07:19:39.341327+00:00 heroku[web.1]: Process exited with status 1
2021-09-02T07:19:39.636801+00:00 heroku[web.1]: State changed from starting to crashed
2021-09-02T12:45:48.327297+00:00 heroku[web.1]: State changed from crashed to starting
2021-09-02T12:45:52.218984+00:00 heroku[web.1]: Starting process with command `java -Dserver.port=28736 $JAVA_OPTS -jar target/XXX.jar`
2021-09-02T12:45:54.207103+00:00 app[web.1]: Create a Procfile to customize the command used to run this process: https://devcenter.heroku.com/articles/procfile
2021-09-02T12:45:54.250429+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2021-09-02T12:45:54.256963+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -Xmx300m -Xss512k -XX:CICompilerCount=2 -Dfile.encoding=UTF-8
2021-09-02T12:45:54.426793+00:00 app[web.1]: no main manifest attribute, in target/XXX.jar
2021-09-02T12:45:54.485594+00:00 heroku[web.1]: Process exited with status 1
2021-09-02T12:45:54.641187+00:00 heroku[web.1]: State changed from starting to crashed
2021-09-02T15:51:38.369534+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=springboot-exp.herokuapp.com request_id=8c88bc1a-aae7-4c0e-9daa-b7ef602d2c47 fwd="71.69.151.195" dyno= connect= service= status=503 bytes= protocol=https
2021-09-02T15:51:38.626347+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=springboot-exp.herokuapp.com request_id=9e2333ec-26a8-46f5-b770-2565a59ef57d fwd="71.69.151.195" dyno= connect= service= status=503 bytes= protocol=https
2021-09-02T15:53:34.736916+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=springboot-exp.herokuapp.com request_id=0025da95-bb22-41b7-a085-63bf5664a7c5 fwd="71.69.151.195" dyno= connect= service= status=503 bytes= protocol=https
2021-09-02T15:53:34.885977+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=springboot-exp.herokuapp.com request_id=bbc9f8b4-a65f-4c95-9d2a-ce9d1b69ab02 fwd="71.69.151.195" dyno= connect= service= status=503 bytes= protocol=https
2021-09-02T15:53:54.458780+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=springboot-exp.herokuapp.com request_id=ceabd4ad-f5f3-4e35-b6e7-d0ca003df0b9 fwd="71.69.151.195" dyno= connect= service= status=503 bytes= protocol=https
2021-09-02T15:53:54.599062+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=springboot-exp.herokuapp.com request_id=463f5577-efbd-4d79-ad85-70462d20eaca fwd="71.69.151.195" dyno= connect= service= status=503 bytes= protocol=https

Answer

As it turns out the failing logs mentions that a Procfile is needed for Heroku and a Spring Boot Application.

Taken from Spring Docs: To customize Heroku builds, we need to provide a Procfile, which provides the incantation required to deploy an application. Heroku assigns a port for the Java application to use and then ensures that routing to the external URI works.

we must configure our application to listen on the correct port. Here’s the Procfile for a starter REST application:

web: java -Dserver.port=$PORT -jar target/demo-0.0.1-SNAPSHOT.jar
Advertisement