出现错误 无法加载架构 abc.xsd。IllegalArgumentException:资源路径 def.xsd 已标准化为 null,这是无效的

Bas*_*sit 5 xsd spring-ws java-8 spring-4

我曾经jaxb2-maven-plugin从 xsd 生成 java 类。类正在生成。下面是我的 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>
Run Code Online (Sandbox Code Playgroud)

从 xsd 生成类后。我正在尝试建立一个 Spring Web 服务。这是我的 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>
Run Code Online (Sandbox Code Playgroud)

现在,当我运行我的项目时,出现以下错误

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
Run Code Online (Sandbox Code Playgroud)

在我中CustomerServiceOperations.xsd,我使用以下行

<xsd:import namespace="http://transactionresult.types.lmsapi.message.webservice.lms.vu360.softech.com" schemaLocation="../types/TransactionResultType.xsd"/>
Run Code Online (Sandbox Code Playgroud)

现在schemaLocation="../types/TransactionResultType.xsd"正在制造问题。虽然它是正确的,因为如果我单击../types/TransactionResultType.xsd,它将打开正确的文件。现在 spring 正在/[/../types/TransactionResultType.xsd]. 我该如何解决这个问题?

谢谢

Jag*_*thi 1

设置uriResolverdefaultURIResolver

CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(schema);
collection.setUriResolver(new DefaultURIResolver());
Run Code Online (Sandbox Code Playgroud)

Java - Spring Ws - 在 XSD 文件中加载相对包含 (Tomcat 8)