0
我想通過xsds驗證傳入的jsons。我公開了幾個服務,並且每個服務都有不同的JSON,每個映射到不同的POJO。所以我寫了一個主xsd,它將包含JSON的所有根元素作爲子元素,並將導入相應的xsds。Apache CXF - 請求Bean錯誤
現在的問題是,我始終得到此異常:
WARNING: javax.xml.bind.UnmarshalException
- with linked exception:
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'RequestBean'.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement
我的XSD是:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/RequestBean"
xmlns:tns="http://www.example.org/RequestBean" elementFormDefault="unqualified"
xmlns:poi="http://www.example.org/PoiRequest" xmlns:sendcar="http://www.example.org/SendCar">
<xs:import namespace="http://www.example.org/PoiRequest"
schemaLocation="PoiRequest.xsd"/>
<xs:import namespace="http://www.example.org/SendCar"
schemaLocation="SendCar.xsd"/>
<xs:element name="RequestBean">
<xs:complexType>
<xs:all>
<xs:element name="PoiRequest" type="poi:PoiRequest" minOccurs="0"/>
<xs:element name="SendCar" type="sendcar:SendCar" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
我的配置是如下:
<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
<ref bean="PoiSearch" />
<ref bean="SendCar" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="dropRootElement" value="true" />
<property name="supportUnwrapped" value="true" /> </bean>
</jaxrs:providers>
<jaxrs:schemaLocations>
<jaxrs:schemaLocation>file:C:\Desktop\xsds\RequestBean.xsd</jaxrs:schemaLocation> <jaxrs:schemaLocation>file:C:\Desktop\xsds\PoiRequest.xsd</jaxrs:schemaLocation>
<jaxrs:schemaLocation>file:C:\Desktop\xsds\Route.xsd</jaxrs:schemaLocation>
<jaxrs:schemaLocation>file:C:\Desktop\xsds\Poi.xsd</jaxrs:schemaLocation>
<jaxrs:schemaLocation>file:C:\Desktop\xsds\SendCar.xsd</jaxrs:schemaLocation>
</jaxrs:schemaLocations>
</jaxrs:server>
是的,它只是關於targetNamespace,我是這個整個xml模式的新手。但經過一些命中和審判後,我刪除了這個屬性,並說它工作。 – Sikorski