本文介紹了JAXB錯(cuò)誤:有多個(gè)映射。由于兩個(gè)對(duì)象工廠具有相同的Bean的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有兩個(gè)Maven JAXB項(xiàng)目。
A:主Maven JAXB存根XSD項(xiàng)目,其中包含BASKET.xsd
B:Maven JAXB存根用戶-希望將BASKET.xsd包裝在自己的對(duì)象中的項(xiàng)目。
這會(huì)產(chǎn)生兩個(gè)對(duì)象工廠(不同的包),它們都聲明了以下內(nèi)容…
@XmlElementDecl(namespace = "http://www.bob.org/bob/namespace/", name = "Basket")
public JAXBElement<BasketType> createBasket(BasketType value) {
return new JAXBElement<BasketType>(QNAME, BasketType.class, null, value);
}
此生成是通過(guò)此插件完成的。
Org.jvnet.jaxb2.maven2
Maven-jaxb2-plugin
0.13.2
在應(yīng)用程序啟動(dòng)時(shí),收到CXF-RT-Frotnend-jaxrs3.1.11提示錯(cuò)誤…
017-07-03 14:38:54,613845801: WARN : [RMI TCP Connection(3)-127.0.0.1] [] org.apache.cxf.jaxrs.utils.ResourceUtils: No JAXB context can be created
com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
The element name {http://www.bob.org/bob/namespace/}Basket has more than one mapping.
this problem is related to the following location:
at public javax.xml.bind.JAXBElement com.bob.bean.ObjectFactory.createBasket(org.bob.BasketType)
at com.bob.bean.ObjectFactory
this problem is related to the following location:
at public javax.xml.bind.JAXBElement org.userservice.bean.ObjectFactory.createBasket(org.bob.BasketType)
在從CXF 2.7.7升級(jí)到3.1.11之前,這不是我收到的錯(cuò)誤
有人知道有沒(méi)有辦法讓maven-jaxb2-plugin不生成方法createBasket(..)在UserService對(duì)象工廠??
還是讓CXF接受兩個(gè)ObjectFactoty類上相同的兩個(gè)方法?
推薦答案
我的解決方案是更改
<property name="singleJaxbContext" value="true"/>
至
<property name="singleJaxbContext" value="false"/>
例如在我的應(yīng)用程序-config.xml中
<bean id="jaxbextprovider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="singleJaxbContext" value="false"/>
</bean>
這篇關(guān)于JAXB錯(cuò)誤:有多個(gè)映射。由于兩個(gè)對(duì)象工廠具有相同的Bean的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,