有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在Heroku成功部署后出现java应用程序错误

我有一个SpringBoot项目在IntellijIDE中运行良好,我尝试在Heroku服务器上部署它。该项目已成功部署,但当我试图从POSTMAN访问它时,出现了503错误:服务不可用

以下是Heroku成功部署后的日志记录:

-----> Building on the Heroku-20 stack
-----> Java app detected
-----> Installing JDK 1.8... done
-----> Executing Maven
       $ ./mvnw -DskipTests clean dependency:list install
       [INFO] Scanning for projects...
       [INFO] 
       [INFO] ----------------< io.slcoder:authentication-server >-----------------
       [INFO] Building authentication-server 0.0.1-SNAPSHOT
       [INFO] --------------------------------[ war ]---------------------------------
       [INFO] 
       [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ authentication-server ---
       [INFO] 
       [INFO] --- maven-dependency-plugin:3.1.2:list (default-cli) @ authentication-server ---
       [INFO] 
       [INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ authentication-server ---
       [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 1 resource
       [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) @ authentication-server ---
       [INFO] Changes detected - recompiling the module!
       [INFO] Compiling 9 source files to /tmp/build_d09a68b1_/target/classes
       [INFO] 
       [INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ authentication-server ---
       [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_d09a68b1_/src/test/resources
       [INFO] 
       [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ authentication-server ---
       [INFO] Changes detected - recompiling the module!
       [INFO] Compiling 1 source file to /tmp/build_d09a68b1_/target/test-classes
       [INFO] 
       [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ authentication-server ---
       [INFO] Tests are skipped.
       [INFO] 
       [INFO] --- maven-war-plugin:3.3.1:war (default-war) @ authentication-server ---
       [INFO] Packaging webapp
       [INFO] Assembling webapp [authentication-server] in [/tmp/build_d09a68b1_/target/authentication-server-0.0.1-SNAPSHOT]
       [INFO] Processing war project
       [INFO] Building war: /tmp/build_d09a68b1_/target/authentication-server-0.0.1-SNAPSHOT.war
       [INFO] 
       [INFO] --- spring-boot-maven-plugin:2.4.1:repackage (repackage) @ authentication-server ---
       [INFO] Replacing main artifact with repackaged archive
       [INFO] 
       [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ authentication-server ---
       [INFO] Installing /tmp/build_d09a68b1_/target/authentication-server-0.0.1-SNAPSHOT.war to /tmp/codon/tmp/cache/.m2/repository/io/slcoder/authentication-server/0.0.1-SNAPSHOT/authentication-server-0.0.1-SNAPSHOT.war
       [INFO] Installing /tmp/build_d09a68b1_/pom.xml to /tmp/codon/tmp/cache/.m2/repository/io/slcoder/authentication-server/0.0.1-SNAPSHOT/authentication-server-0.0.1-SNAPSHOT.pom
       [INFO] ------------------------------------------------------------------------
       [INFO] BUILD SUCCESS
       [INFO] ------------------------------------------------------------------------
       [INFO] Total time:  8.024 s
       [INFO] Finished at: 2021-01-28T20:29:08Z
       [INFO] ------------------------------------------------------------------------
-----> Discovering process types
       Procfile declares types -> (none)
-----> Compressing...
       Done: 149.5M

Heroku的应用程序日志:

2021-01-28T21:06:14.000000+00:00 app[api]: Build started by user slcoder@gmail.com
2021-01-28T21:06:43.212587+00:00 app[api]: Release v12 created by user slcoder@gmail.com
2021-01-28T21:06:43.212587+00:00 app[api]: Deploy f113390b by user slcoder@gmail.com
2021-01-28T21:06:50.000000+00:00 app[api]: Build succeeded
2021-01-28T21:06:55.588865+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=authentication-server-app.herokuapp.com request_id=8710722d-c858-423a-bb8b-9268ef8318f3 fwd="196.74.101.204" dyno= connect= service= status=503 bytes= protocol=https
2021-01-28T21:06:59.516531+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=authentication-server-app.herokuapp.com request_id=0d6f4102-5dba-44b4-b717-d6d732d236bd fwd="196.74.101.204" dyno= connect= service= status=503 bytes= protocol=https
2021-01-29T00:17:50.789994+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=authentication-server-app.herokuapp.com request_id=fcba05fd-3c76-4830-af3e-dfc697b2f190 fwd="196.74.101.204" dyno= connect= service= status=503 bytes= protocol=https
2021-01-29T00:17:52.530644+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=authentication-server-app.herokuapp.com request_id=77736faf-0206-49dc-80be-3a1c0b5f061a fwd="196.74.101.204" dyno= connect= service= status=503 bytes= protocol=https
2021-01-29T11:20:59.963444+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=authentication-server-app.herokuapp.com request_id=c66098e0-1893-4d3f-90e3-e08f3afe0cea fwd="160.177.175.70" dyno= connect= service= status=503 bytes= protocol=https
2021-01-29T11:21:02.909523+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=authentication-server-app.herokuapp.com request_id=ee94b09c-f8c8-4783-a951-0c511007f93f fwd="160.177.175.70" dyno= connect= service= status=503 bytes= protocol=https

这是我的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.4.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.slcoder</groupId>
    <artifactId>authentication-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>authentication-server</name>
    <description>Server dedicated to authentication</description>
    <packaging>war</packaging>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

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

</project>

应用程序。属性

spring.datasource.url=jdbc:mysql://zt9j9hwaktmzqprk:eayk987igm1t1shd@esilxl0nthgloe1y.chr7pe7iynqr.eu-west-1.rds.amazonaws.com:3306/vqa34ov9ga2iumfm
spring.datasource.username=zt9j9hwaktmzqprk
spring.datasource.password=****************
spring.datasource.initialization-mode = always
spring.datasource.max-active=10

有人能帮我吗?提前谢谢


共 (1) 个答案

  1. # 1 楼答案

    最终,核心问题是Heroku不知道如何运行应用程序。您通常会告诉Heroku如何使用Procfile运行应用程序

    然而,由于您正在运行Spring Boot,我们将检测到这一点,并为您编写一个Procfile。这里没有发生这种情况,因为您将应用程序打包为WAR文件,而我们无法将其作为独立应用程序运行

    如果您将Spring Boot打包更改为JAR,Heroku应该会将您的应用检测为Spring Boot应用,而您甚至不需要Procfile。尝试将<packaging>war</packaging>中的<packaging>jar</packaging>更改为pom.xml