首页 > 解决方案 > 部署spring boot应用程序的问题

问题描述

我在部署 Spring Boot 应用程序时遇到问题。
首先我尝试在heroku上部署它,但是出现了错误。
当我试图在本地部署它时出现了同样的错误
这是它:

 ...
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ portfolio_app ---
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ portfolio_app ---
[INFO] Building jar: C:\JetBrains\portfolio_app\target\portfolio_app-1.0-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.3.3.RELEASE:repackage (repackage) @ portfolio_app ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ portfolio_app ---
[INFO] Installing C:\JetBrains\portfolio_app\target\portfolio_app-1.0-SNAPSHOT.jar to C:\Users\matni\.m2\repository\eu\mnrdesign\matned\portfolio_app\1.0-SNAPSHOT\portfolio_app-1.0-SNAPSHOT.jar
[INFO] Installing C:\JetBrains\portfolio_app\pom.xml to C:\Users\matni\.m2\repository\eu\mnrdesign\matned\portfolio_app\1.0-SNAPSHOT\portfolio_app-1.0-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ portfolio_app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.996 s
[INFO] Finished at: 2020-09-29T10:02:24+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project portfolio_app: Deployment failed: repository element was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

我想这是我的 pom 的问题:

    <?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 http://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.3.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.group.nden</groupId>
    <artifactId>portfolio_app</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>portfolio_app</name>
    <description>desc</description>
    <url>http://maven.apache.org</url>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <!--        SPRING BOOT-->
        <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>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!--        SPRING BOOT-->

        <!--        THYMELEAF-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
            <version>3.0.11.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity4</artifactId>
            <version>3.0.4.RELEASE</version>
        </dependency>
        <!--        THYMELEAF-->

        <!--        SESSION-->
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-jdbc</artifactId>
        </dependency>
        <!--        SESSION-->

        <!--        DATABASE-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <!--        DATABASE-->
        <!--        PROGRAMING-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <!--        PROGRAMING-->

        <!--        VALIDATION-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
        <!--        VALIDATION-->

        <!--        CAPTCHA-->
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.30.10</version>
        </dependency>
        <!--        CAPTCHA-->

        <!--         MAIL   -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
            <version>2.2.5.RELEASE</version>
        </dependency>
        <!--         MAIL   -->

        <!--        TESTING-->
        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock-standalone</artifactId>
            <version>2.26.3</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.5.10</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!--        TESTING-->

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.heroku.sdk</groupId>
                <artifactId>heroku-maven-plugin</artifactId>
                <version>3.0.3</version>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-configuration-processor</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我不知道该怎么做。
我把它放在一个公共存储库中,所以任何敏感数据都不会在那里......
最好的事情是我有几乎相同的应用程序
和几乎相同的 pom,一切都很好。
我很困惑。

标签: spring-bootmavenherokudeploymentmaven-plugin

解决方案


最后我解决了这个问题。
首先,我必须在 pom.xml 中创建一个存储库

    <distributionManagement>
    <repository>
        <id>myrepository</id>
        <url>file:.mvn/maven-repo</url>
    </repository>
</distributionManagement>

比我不得不用 java 版本删除繁荣(来自 pom.xml)。
我在我的应用程序的主文件夹中创建了一个 system.properities。
那里我放了java版本,这个:

java.runtime.version=11

比我必须做的简单 'mvn deploy'
然后 heroku 想要我的应用程序。
工作正常。


推荐阅读