【问题标题】:Caused by: java.lang.RuntimeException: Cannot run Liquibase, liquibase.datasource is not set原因:java.lang.RuntimeException:无法运行 Liquibase,未设置 liquibase.datasource
【发布时间】:2016-10-26 21:45:15
【问题描述】:

在我的 pom.xml 中配置 liquibase 之后。我还在资源文件夹 changelog.xml 中添加了这些文件,这就是内容

<databaseChangeLog xmlns='http://www.liquibase.org/xml/ns/dbchangelog'
      xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
      xsi:schemaLocation='http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd'>
      <changeSet id="001" author="Dev">
        <sql>
          ALTER TABLE book ADD COLUMN address VARCHAR(1024);
        </sql>
      </changeSet>
    </databaseChangeLog>

我还在资源文件夹中添加了这个文件 liquibase.properties,这就是内容

contexts: ${liquibase.contexts} 
changeLogFile: src/main/resources/changelog.xml 
driver: ${jdbc.driverClassName} 
url: ${jdbc.url} 
username: ${jdbc.username} 
verbose: true 
dropFirst: false

我也像这样配置了我的 pom.xml

<plugin>
           <groupId>org.liquibase</groupId>
           <artifactId>liquibase-maven-plugin</artifactId>
           <version>3.0.5</version>
           <configuration>                  
              <propertyFile>src/main/resources/liquibase.properties</propertyFile>
           </configuration>                
           <executions>
             <execution>
               <phase>process-resources</phase>                                                                  
               <goals>
                 <goal>update</goal>
               </goals>
             </execution>
           </executions>

        </plugin>

当我启动我的项目时,我从 tomcat 收到此错误

Caused by: java.lang.RuntimeException: Cannot run Liquibase, liquibase.datasource is not set

请问有什么问题?

【问题讨论】:

  • 您是否启用了资源过滤(使用 maven)?
  • 请给我看看
  • 我创建了一个chat room。也许我可以给你一些提示......

标签: java spring hibernate maven liquibase


【解决方案1】:

如果您在 liquibase.properties 文件中使用占位符,您还必须在 pom.xml 中使用以下元素启用资源过滤:

<build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    ...
</build>

(如果你不这样做:liquibase.properties 将保留像

这样的东西
url: ${jdbc.url}

当然,这不是一个有效的网址。)

【讨论】:

  • 还是同样的问题原因:java.lang.RuntimeException:无法运行Liquibase,未设置liquibase.datasource
  • 我做了一个 maven 构建,之后我的 changelog.xml 中出现此错误 >>>>> cvc-elt.1:找不到元素“databaseChangeLog”的声明。
  • 确保你的执行目录是你的项目根目录。
  • 我正在执行这样的项目>>>>右键单击项目>>>>>选择运行方式>>>>>>然后在服务器上运行。
  • src/main/resources 不存在“在服务器上”。更改日志文件位于类路径的根目录。
猜你喜欢
  • 2020-06-25
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-28
相关资源
最近更新 更多