xsd - 出现错误 无法加载架构 abc.xsd。 IllegalArgumentException : The resource path def. xsd 已规范化为无效的 null

标签 xsd java-8 spring-ws spring-4

我使用 jaxb2-maven-plugin 从 xsd 生成 java 类。类(class)正在生成。下面是我的一个 xsd 文件的示例

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://customer.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns="http://customer.serviceoperations.lmsapi.message.webservice.lms.vu360.softech.com" 
    xmlns:cust="http://customer.types.lmsapi.message.webservice.lms.vu360.softech.com"
    xmlns:tr="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

    <xsd:import namespace="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/TransactionResultType.xsd"/>
    <xsd:import namespace="http://customer.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/Customer.xsd"/>

    <xsd:element name="AddCustomerRequest">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="Customers" type="cust:Customers" minOccurs="1" maxOccurs="1" nillable="false" />
            </xsd:sequence>
            <xsd:attribute name="key" type="xsd:string" use="required" />
            <xsd:attribute name="ResellerId" type="xsd:nonNegativeInteger" use="required" />
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="AddCustomerResponse">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="RegisterCustomers" type="cust:RegisterCustomers" minOccurs="0" maxOccurs="1" nillable="false" />
            </xsd:sequence>
            <xsd:attribute name="transactionResult" type="tr:TransactionResultType" use="required"/>
            <xsd:attribute name="transactionResultMessage" type="xsd:string"/>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>

从 xsd 生成类之后。我正在尝试建立一个 spring 网络服务。这是我的 spring 网络服务配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                    ...  
                    http://www.springframework.org/schema/web-services/web-services-2.2.xsd ">

    <context:component-scan base-package="pk.training.basitmahmood.webservice.endpoints.impl"/> 

    <bean id="LmsApi" class="org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition" lazy-init="true">  
        <property name="schemaCollection" ref="lmsApiSchema" />  
        <property name="portTypeName" value="LmsApiPortType"/>  
        <property name="serviceName" value="LmsApiServices" />  
        <property name="locationUri" value="/endpoints"/>  
    </bean> 

    <bean id="lmsApiSchema" class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">  
        <property name="inline" value="true" />  
        <property name="xsds">  
            <list>  
                <value>schemas/lmsapi/serviceoperations/CustomerServiceOperations.xsd</value>
                <value>schemas/lmsapi/serviceoperations/EnrollmentServiceOperations.xsd</value>
                 ...
                <value>schemas/lmsapi/types/Address.xsd</value>
                 ...
                <value>schemas/lmsapi/utility/OrgGroupUtility.xsd</value>
                <value>schemas/lmsapi/utility/utility.xsd</value>
            </list>  
        </property>  
    </bean>

</beans>

现在,当我运行我的项目时,出现以下错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'lmsApiSchema' defined in ServletContext resource [/WEB-INF/spring/appServlet/webservices-context.xml]: Invocation of init method failed; nested exception is org.springframework.xml.xsd.commons.CommonsXsdSchemaException: Schema [ServletContext resource [/schemas/lmsapi/serviceoperations/CustomerServiceOperations.xsd]] could not be loaded; nested exception is java.lang.IllegalArgumentException: The resource path [/../types/TransactionResultType.xsd] has been normalized to [null] which is not valid
....
Caused by: org.springframework.xml.xsd.commons.CommonsXsdSchemaException: Schema [ServletContext resource [/schemas/lmsapi/serviceoperations/CustomerServiceOperations.xsd]] could not be loaded; nested exception is java.lang.IllegalArgumentException: The resource path [/../types/TransactionResultType.xsd] has been normalized to [null] which is not valid
...
Caused by: java.lang.IllegalArgumentException: The resource path [/../types/TransactionResultType.xsd] has been normalized to [null] which is not valid

在我的 CustomerServiceOperations.xsd 中,我使用以下行
<xsd:import namespace="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/TransactionResultType.xsd"/>

现在 schemaLocation="../types/TransactionResultType.xsd" 正在制造问题。虽然这是正确的,因为如果我点击 ../types/TransactionResultType.xsd ,它会打开正确的文件。现在 spring 在 / 之类的路径之前附加 [/../types/TransactionResultType.xsd] 。我该如何解决这个问题?

谢谢

最佳答案

uriResolver 设置为 defaultURIResolver

CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(schema);
collection.setUriResolver(new DefaultURIResolver());

Java - Spring Ws - Loading Relative Includes in XSD files (Tomcat 8)

关于xsd - 出现错误 无法加载架构 abc.xsd。 IllegalArgumentException : The resource path def. xsd 已规范化为无效的 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27320584/

相关文章:

xml - 重新定义 xsd 元素

java - Maven 无法找到 org.springframework.ws :spring-ws:1. 5.8

java - 推荐java框架加载WSDL url/文件,获取方法列表等

xsd - 如何将XSD转换为Ecore(EMF)

xsd - XML 模式的公共(public)托管

java - FunctionalInterface Comparator 有 2 个抽象方法

带有自定义单元格工厂的 javafx ListView 不保留所选单元格

java - Spring-ws客户端mtom

xml - 从另一个 XSD 导入复杂类型

java - 我的 ImmutableList 收集器不工作?