【问题标题】:Liquibase cannot find parserLiquibase 找不到解析器
【发布时间】:2016-01-06 11:40:58
【问题描述】:

我在运行更新时遇到 Liquibase 异常。

Caused by: liquibase.exception.UnknownChangelogFormatException: 
Cannot find parser that supports <?xml version="1.0" encoding="UTF-8" standalone="no"?>

我认为 Liquibase 默认支持 xml 解析,所以我不确定这里的情况。初始化类时是否缺少配置?

  private lazy val liquibase: Liquibase = {
    val fsFO: ResourceAccessor = new FileSystemResourceAccessor
    val clFO: ResourceAccessor = new ClassLoaderResourceAccessor
    val contextClassLoader = Thread.currentThread().getContextClassLoader
    val threadClFO: ResourceAccessor = new ClassLoaderResourceAccessor(contextClassLoader)
    val database = DatabaseFactory.getInstance.findCorrectDatabaseImplementation(new JdbcConnection(connection))
    new Liquibase(changeLog, new CompositeResourceAccessor(clFO, fsFO, threadClFO), database)
  }

  def update(): Unit = Try(liquibase.update(context)) match {
    case Success(_) => log.info("LIQUIBASE FINISHED: Update change log")
    case Failure(ex) => throw new Exception("LIQUIBASE FAILED: Update change log", ex)
  }

变量changelog是使用`java.o.File

读取的String
  val fileReader = new FileReader(file)
  val characters = new Array[Char](file.length().toInt)
  fileReader.read(characters)
  new String(characters)

Master.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
    <changeSet author="author" id="1444318866725-1">
        <createTable tableName="author">
            <column name="id" type="INT">
                <constraints nullable="false"/>
            </column>
            <column defaultValue="NULL::character varying" name="first_name" type="VARCHAR(255)"/>
            <column defaultValue="NULL::character varying" name="last_name" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>
    <changeSet author="author" id="1444318866725-2">
        <addPrimaryKey columnNames="id" constraintName="author_pkey" tableName="author"/>
    </changeSet>
    <changeSet author="author" id="add-column-gender">
        <dropColumn tableName="author">
            <column name="first_name"/>
        </dropColumn>
        <addColumn tableName="author">
            <column name="gender" type="varchar(255)"/>
        </addColumn>
    </changeSet>
</databaseChangeLog>

【问题讨论】:

  • Liquibase 确实支持 XML 格式的变更日志,因此您在某处配置错误。您可以包含您的更改日志文件吗?另外,当您创建新的 Liquibase 对象时,变量“changelog”的类型和值是什么?
  • @SteveDonie 请在上面找到
  • @SteveDonie 感谢您指出 changeLog 变量。我发现我不应该从文件中读取。你介意把你的答案放在下面吗?我很想感谢你。
  • 我不知道 Scala,但是您没有向 FileReader 提供任何编码信息,也许它不是以 UTF-8 格式读取文件,而是以其他方式读取文件(前提是文件 以 UTF-8 存储)。 Liquibase 还有一个构造函数,您只需将File 传递给它,而不是字符串

标签: scala database-migration liquibase


【解决方案1】:

问题似乎在于changeLog 变量不是包含更改日志文件路径的String

【讨论】:

  • 为了澄清,您只需将类路径作为更改日志传递。您不需要从文件中读取。
猜你喜欢
  • 1970-01-01
  • 2016-10-03
  • 2017-10-12
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 2022-01-04
  • 2012-03-11
  • 2014-06-23
相关资源
最近更新 更多