spring - 在 EclipseLink MOXy 中使用多重继承

标签 spring jaxb eclipselink moxy

我正在尝试使用 spring( @Autowire Jaxb 模型类中的注释)

.....

@XmlAttribute(name = "object-id")
@XmlSchemaType(name = "positiveInteger")
protected BigInteger objectId;

@XmlTransient
@Autowired MediationCacheManager cacheManager;

哪里MediationCacheManager由三个接口(interface)扩展而来

在创建 JaxbContext 时,我捕获了一个异常: Exception [EclipseLink-50089] (Eclipse Persistence Services - 2.5.0.v20121116-8650760): org.eclipse.persistence.exceptions.JAXBException Exception Description: The java interface com.netcracker.mediation.common.caches.api.MediationCacheManager can not be mapped by JAXB as it has multiple mappable parent interfaces. Multiple inheritence is not supported

当然,我知道 eclipselink 不支持多重继承,但我如何跳过 cacheManager来自 Jaxb 处理的字段?至于我 - 应该由 XmlTransient 完成注释但它不起作用。你有什么想法吗?

最佳答案

您看到的问题对应于我们在 EclipseLink 2.5.1 和 2.6.0 流中修复的错误 ( http://bugs.eclipse.org/411993 )。从 2013 年 7 月 4 日开始,您可以通过以下链接下载夜间版本:


解决方法

您可以使用 MOXy 的外部映射文档来覆盖 MediationCacheManager 的父类(super class)型,以使您的用例正常工作(请参阅:http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html):

oxm.xml

<?xml version="1.0"?>
<xml-bindings
    xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
    package-name="forum17458822">
    <java-types>
        <java-type name="MediationCacheManager" super-type="java.lang.Object"/>
    </java-types>
</xml-bindings>

演示

import java.util.*;
import javax.xml.bind.JAXBContext;
import org.eclipse.persistence.jaxb.JAXBContextProperties;

public class Demo {

    public static void main(String[] args) throws Exception {
        Map<String, Object> properties = new HashMap<String, Object>(1);
        properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, "forum17458822/oxm.xml");
        JAXBContext jc = JAXBContext.newInstance(new Class[] {Foo.class}, properties);
    }

}

关于spring - 在 EclipseLink MOXy 中使用多重继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17458822/

相关文章:

mysql - 在 Google App Engine 开发环境中使用 JPA 时,非 Ascii 字符保存为 '?'

java - 尝试访问备注字段时出错(EclipseLink、JdbcOdbc、Clob)

java - Spring 分段上传

java - 接收 XML 格式的列表

java - Spring Boot : "Cannot set level: INFO, ERROR for ' org. springframework'"使用 logback-spring.xml

java - JAXB - 生成的类实现接口(interface)

java - JAXB 返回 null

java - JPA Left Join IS NULL 条件不起作用

java - 如果/否则在 thymeleaf 中

Spring-data-rest 和 Spring-jpa