【问题标题】:Error: The database URL has not been specified either as a parameter or in a properties file when trying to perform a rollback错误:尝试执行回滚时,未将数据库 URL 指定为参数或属性文件
【发布时间】:2021-06-03 07:57:53
【问题描述】:

我正在尝试执行回滚,但出现以下错误

The database URL has not been specified either as a parameter or in a properties file.´

我的 pom 文件中确实有数据库 URL,如下所示,所以我认为这不是问题

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 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.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.petapilot</groupId>
    <artifactId>migrations</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Migrations</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>15</java.version>
        <liquibase.mysql.url>jdbc:mysql://127.0.0.1:3306</liquibase.mysql.url>
        <liquibase.mysql.username>root</liquibase.mysql.username>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>4.3.1</version>
        </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.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
    </dependencies>

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

</project>

数据库有密码。我也必须写吗? 我该如何解决这个问题?

【问题讨论】:

    标签: java maven liquibase


    【解决方案1】:

    我不确定通过 pom.xml 文件配置 Liquibase 的方式。我认为您可以尝试这种方式:

    • 不要在 pom.xml 的标签内提供所有数据库属性,而是创建“liquibase.properties”并在此文件中填充与 liquibase(DB) 相关的各种属性。 有关创建“liquibase.properties”文件的帮助,请访问this link

    • 尝试在现有的 pom.xml 文件中使用类似于以下的配置:

    
        <modelVersion>4.0.0</modelVersion>
            <groupId>com.my-group.app</groupId>
            <artifactId>Liqui<SampleDb>-app</artifactId>
            <version>1.0-SNAPSHOT</version>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>org.liquibase</groupId>
                            <artifactId>liquibase-maven-plugin</artifactId>
                            <version>3.9.0</version>
                            <configuration>
                                <propertyFile>liquibase.properties</propertyFile>
                            </configuration>
                            <dependencies>
                              <dependency>
                                  <groupId><db_type></groupId>
                                  <artifactId><db_type></artifactId>
                              </dependency>
                          </dependencies>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
    
    • 您也可以通过更正现有的 pom 文件来尝试以下方法。 This link 表示在 &lt;configuration&gt; 部分中包含 liquibase 属性。可以尝试在您的 POM 文件中的 &lt;configuration&gt; 部分中围绕 liquibase 属性,如下所示:
    <configuration>
        <changeLogFile>changelog.xml</changeLogFile>
        <url>MyJDBCConnection</url>
        <username>dbuser</username>
        <password>dbpassword</password>
    </configuration>
    

    是的,配置需要数据库密码

    干杯!!

    【讨论】:

    • 谢谢,它成功了。我使用了 liquibase.properties 方法
    • 太棒了!无论如何,属性文件都是简洁且推荐的方式。很高兴知道它有帮助!
    • 使用&lt;configuration&gt; 部分对我的情况很有帮助。
    猜你喜欢
    • 2021-12-28
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 2014-06-06
    • 1970-01-01
    • 2017-07-20
    • 1970-01-01
    相关资源
    最近更新 更多