如何通过JavaFX在package-info.java的@XmlSchema中配置Liquibase XML Schema
解决方案
你可以直接使用以下配置替换package-info.java中的注解部分:
@javax.xml.bind.annotation.XmlSchema( // 全局默认命名空间,对应根节点无前缀的xmlns配置 namespace = "http://www.liquibase.org/xml/ns/dbchangelog", // 所有元素默认携带命名空间配置 elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, // 命名空间与前缀映射关系 xmlns = { @javax.xml.bind.annotation.XmlNs(prefix = "", namespaceURI = "http://www.liquibase.org/xml/ns/dbchangelog"), @javax.xml.bind.annotation.XmlNs(prefix = "xsi", namespaceURI = "http://www.w3.org/2001/XMLSchema-instance") }, // 对应xsi:schemaLocation的完整取值 location = "http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd" ) package my.package.name; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNsForm;
配置说明
elementFormDefault设为QUALIFIED是必要配置,保证当前包下生成的所有XML元素默认继承全局命名空间,不会出现无命名空间的无效元素xmlns数组中配置的xsi前缀是xsi:schemaLocation属性生效的前置依赖- 若序列化时没有自动输出schemaLocation,可在Marshaller实例化后额外添加配置:
marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "上述location属性的完整字符串"),该配置优先级高于注解配置
内容的提问来源于stack exchange,提问作者thorald_
相关产品推荐
相关产品推荐

