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

Heroku为Spring Boot REST API部署构建失败

慕铭
2023-03-14

我在本地有一个Spring Boot REST API。

它正在成功地生成。当我运行mvn clean package时,war文件在本地。

现在我想把它部署到Heroku。

这些就是我所做的步骤。

>

  • 将代码上传到github respository。比如说\myrestapi。

    打开终端以运行Heroku CLI命令

    登录heroku

    heroku登录

    运行命令在heroku上创建应用程序

    heroku创建myrestapi

    这个命令不起作用。收到消息说“myrestapi”这个名字已经存在了。

    所以我把名字改成了别的名字。让我们说“cl myrestapi”:

    创建cl-myrestapi

    它运行成功。

    运行命令在heroku上创建免费的postgreSQL数据库:

    heroku插件:创建heroku postgresql:hobby dev

    Git push

    git push heroku main

    这将成功启动下载。

    但随后会生成以下错误:

        remote:        [INFO] BUILD FAILURE
        remote:        [INFO] ------------------------------------------------------------------------
        remote:        [INFO] Total time:  14.653 s
        remote:        [INFO] Finished at: 2021-02-19T18:43:12Z
        remote:        [INFO] ------------------------------------------------------------------------
        remote:        [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-
        compile) on project myrestapi: Fatal error compiling: invalid target release: 11 -> [Help 1]
        remote:        [ERROR]
        remote:        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
        remote:        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
        remote:        [ERROR]
        remote:        [ERROR] For more information about the errors and possible solutions, please read the following artic
        les:
        remote:        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
        remote:
        remote:  !     ERROR: Failed to build app with Maven
        remote:        We're sorry this build is failing! If you can't find the issue in application code,
        remote:        please submit a ticket so we can help: https://help.heroku.com/
        remote:
        remote:  !     Push rejected, failed to compile Java app.
        remote:
        remote:  !     Push failed
        remote:  !
        remote:  ! ## Warning - The same version of this code has already been built: e11a85238783f54ee30765ba4f8a55354930be
        09
        remote:  !
        remote:  ! We have detected that you have triggered a build from source code with version e11a85238783f54ee30765ba4f
        8a55354930be09
        remote:  ! at least twice. One common cause of this behavior is attempting to deploy code from a different branch.
        remote:  !
        remote:  ! If you are developing on a branch and deploying via git you must run:
        remote:  !
        remote:  !     git push heroku <branchname>:main
        remote:  !
        remote:  ! This article goes into details on the behavior:
        remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
        remote:
        remote: Verifying deploy...
        remote:
        remote: !       Push rejected to cl-myrestapi.
        remote:
        To https://git.heroku.com/cl-myrestapi.git
         ! [remote rejected] main -> main (pre-receive hook declined)
        error: failed to push some refs to 'https://git.heroku.com/cl-myrestapi.git'
    

    为什么我会出现这个错误,因为它在本地成功构建?

    我只看到两个不同点:

    >

  • 需要在heroku上使用不同的项目名称(参见上面的步骤4)

    应用属性是不同的。

    这是我最初的申请。属性(在本地运行)。

    spring.datasource.url=jdbc:postgresql://localhost:5432/myrestapi
    spring.datasource.username=xxx
    spring.datasource.password=yyy
    spring.datasource.driver-class-name=org.postgresql.Driver
    spring.jpa.hibernate.ddl-auto=update
    

    这是更新后的应用程序。属性(正在上载到heroku)

    spring.datasource.url=${JDBC_DATASOURCE_URL}
    spring.jpa.hibernate.ddl-auto=update
    

    UPATE:注意,当执行git push heroku main命令时,在我使用版本11时,一开始会显示“安装jdk 1.8”。

    所以这似乎是个问题。

    为了解决这个问题,我尝试添加一个系统。属性文件位于根目录下,并显示以下行:

    java。运行时。版本=11

    但没有解决。

  • 共有1个答案

    宗涵蓄
    2023-03-14
    • 首先别忘了在pom中添加这个。xml
    <properties>
            <java.version>11</java.version>
        </properties>
    
    • 第二,检查项目SDK和项目语言级别(在项目结构中),它们都应该是11

    在设置中检查Java编译器,并确保project-byte-code-versionTarget-byte-code-version设置为11。

    • 最后一次机会,如果Heroku不能部署,请尝试在您的pom.xml文件底部。
    
    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>11</source>
                        <target>11</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    
    
    
    
     类似资料:
    • 问题内容: 当我尝试在heroku中进行部署时遇到问题。有趣的是,这是三天前的工作。另外,在本地计算机上工作正常。 Bcrypt的版本是3.0.0,节点8.12.0 我确实需要部署此服务器。您能告诉我如何解决此错误吗?我尝试了一些找到的解决方案,但没有任何效果。我什至尝试卸载并再次安装Bcrypt,但无法正常工作。 谢谢您的帮助。 这是日志。 问题答案: 我也发生了同样的事情。 未在package

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

    • 我想在heroku上有一个tilestream,我遵循了教程,我做了完全相同的事情,并不断得到一个构建/编译错误。 刚刚添加了2个文件和一个目录: Procfile: 包裹json: 空的/平铺方向。 当通过git推送到heroku时,我得到以下错误: 当我去网站时,我得到了错误(检查这里) 我还检查了日志: 以及在heroku上运行的进程: 对于这个例子,我没有将地图上传到./ware目录,但是

    • 我正在为一个业余项目工作Java REST api,我使用Heroku作为我的部署平台。我设法使用部署了应用程序。 检测不到set buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/heroku/java.tgz 更多信息:https://devcenter.heroku.com/articles/buildpacks#d

    • 我的站点是使用Gatsby建立的,并持续部署Netlify。我已经两个月没碰过我的盖茨比网站了。因此,当我运行更新、添加新内容和部署时,在Netlify构建上遇到了一个中断错误。 尝试了很多事情,花了太多时间在上面。最初我只使用NPM。在坚持了一段时间之后,我按照一些在线线程的建议,转到了纱线。现在使用yarn得到不同的错误消息,但部署到Netlify仍然没有成功。 这可能是一些愚蠢的简单的事情。

    • 问题内容: 我是Yesod的新手,无法静态构建Yesod,因此可以部署到Heroku。 我已更改默认的.cabal文件以反映静态编译 而且它不再构建。我收到一堆警告,然后是许多未定义的引用,如下所示: 如果我仅使用just进行编译,而没有进行 任何编译,则一切正常,但是当尝试在Heroku上启动时,应用程序崩溃。 我尝试按照此处的建议将libgmp.so.10添加到LD_LIBRARY_PATH