我使用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>
从xsd生成类后。我正在尝试建立一个Spring Web服务。这是我的弹簧
的Web服务配置文件<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]
。我该如何解决这个问题?
由于
答案 0 :(得分:1)
将uriResolver
设置为defaultURIResolver
CommonsXsdSchemaCollection collection = new CommonsXsdSchemaCollection(schema);
collection.setUriResolver(new DefaultURIResolver());
Java - Spring Ws - Loading Relative Includes in XSD files (Tomcat 8)