问题描述
我正在尝试使用spring( @Autowire
注释到Jaxb Model类中)
I'm trying to use spring (@Autowire
annotation into Jaxb Model class)
.....
@XmlAttribute(name = "object-id")
@XmlSchemaType(name = "positiveInteger")
protected BigInteger objectId;
@XmlTransient
@Autowired MediationCacheManager cacheManager;
其中 MediationCacheManager
从三个接口扩展
在创建JaxbContext时,我捕到一个异常:
Exception [EclipseLink-50089](Eclipse Persistence Services - 2.5.0.v20121116- 8650760):org.eclipse.persistence.exceptions.JAXBException
异常说明:JAXB无法映射java接口com.netcracker.mediation.common.caches.api.MediationCacheManager,因为它具有多个可映射的父接口。不支持多重继承
On creation of JaxbContext i catch an exception: Exception [EclipseLink-50089] (Eclipse Persistence Services - 2.5.0.v20121116-8650760): org.eclipse.persistence.exceptions.JAXBExceptionException 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不支持多重继承,但我怎么能跳过来自Jaxb处理的cacheManager
字段?至于我 - 它应该通过 XmlTransient
注释来完成,但它没有用。你知道吗?
Of course i understand that eclipselink doesn't support multiple inheritance but how can i skip cacheManager
field from Jaxb processing? As for me - it should be done by XmlTransient
annotation but its no work. Have u any idea?
推荐答案
你看到的问题对应一个bug()我们已经修复了EclipseLink 2.5.1和2.6.0流。您可以从2013年7月4日开始从以下链接下载每晚构建:
The issue you are seeing corresponds to a bug (http://bugs.eclipse.org/411993) that we have fixed in the EclipseLink 2.5.1 and 2.6.0 streams. You can download a nightly build from the following link starting July 4, 2013:
- http://www.eclipse.org/eclipselink/downloads/nightly.php
替代方法
您可以使用MOXy的外部映射文档以覆盖 MediationCacheManager
的超类型,以使您的用例工作(请参阅:):
You can use MOXy's external mapping document to override the supertype of MediationCacheManager
to make your use case work (see: http://blog.bdoughan.com/2010/12/extending-jaxb-representing-annotations.html):
oxm.xml
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>
演示
Demo
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);
}
}
这篇关于在EclipseLink MOXy中使用多重继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!