Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ApacheCXF-请求Bean错误_Java_Json_Rest_Xsd_Cxf - Fatal编程技术网

Java ApacheCXF-请求Bean错误

Java ApacheCXF-请求Bean错误,java,json,rest,xsd,cxf,Java,Json,Rest,Xsd,Cxf,我试图通过XSD验证传入的JSON。我公开了几个服务,每个服务都有不同的JSON,每个JSON映射到不同的POJO。因此,我编写了一个主xsd,它将包含JSON的所有根元素作为子元素,并将导入相应的xsd 现在的问题是,我总是遇到这样的异常: WARNING: javax.xml.bind.UnmarshalException - with linked exception: Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot

我试图通过XSD验证传入的JSON。我公开了几个服务,每个服务都有不同的JSON,每个JSON映射到不同的POJO。因此,我编写了一个主xsd,它将包含JSON的所有根元素作为子元素,并将导入相应的xsd

现在的问题是,我总是遇到这样的异常:

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>

首先要检查的是名称空间或XML文档元素。您的错误指向一个非限定名称,而您的XSD为RequestBean使用了一个目标命名空间。

是的,这只是关于targetNamespace的,我对整个xml模式都不熟悉。但是经过一番尝试,我删除了这个属性,瞧,它成功了。