我正在尝试在我的Web配置中使用SchemaCollection。但是,当我为此添加代码时,我会收到以下错误:
由: java.lang.IllegalArgumentException: schemaElement引起的不能为null!您是运行afterPropertiesSet()还是将其注册为Spring?
这个错误意味着什么?查看弹簧码,是与XSD上的schemaElement相关的东西,但我不能说什么。
惠特schemaCollection,一切都很好。
完全错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pedidos' defined in class path resource [br/com/company/rdt/config/WebServiceConfig.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: schemaElement must not be null! Did you run afterPropertiesSet() or register this as a Spring bean?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1631) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.17.RELEASE.jar:1.5.17.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.17.RELEASE.jar:1.5.17.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.17.RELEASE.jar:1.5.17.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.17.RELEASE.jar:1.5.17.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.17.RELEASE.jar:1.5.17.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.17.RELEASE.jar:1.5.17.RELEASE]
at br.com.company.rdt.IntegracaoRmsApplication.main(IntegracaoRmsApplication.java:12) [classes/:na]
Caused by: java.lang.IllegalArgumentException: schemaElement must not be null! Did you run afterPropertiesSet() or register this as a Spring bean?
at org.springframework.util.Assert.notNull(Assert.java:134) ~[spring-core-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.xml.xsd.SimpleXsdSchema.getTargetNamespace(SimpleXsdSchema.java:95) ~[spring-xml-2.4.3.RELEASE.jar:na]
at org.springframework.ws.wsdl.wsdl11.provider.InliningXsdSchemaTypesProvider.addTypes(InliningXsdSchemaTypesProvider.java:99) ~[spring-ws-core-2.4.3.RELEASE.jar:na]
at org.springframework.ws.wsdl.wsdl11.ProviderBasedWsdl4jDefinition.afterPropertiesSet(ProviderBasedWsdl4jDefinition.java:234) ~[spring-ws-core-2.4.3.RELEASE.jar:na]
at org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition.afterPropertiesSet(DefaultWsdl11Definition.java:183) ~[spring-ws-core-2.4.3.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1689) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1627) ~[spring-beans-4.3.20.RELEASE.jar:4.3.20.RELEASE]
... 16 common frames omittedbean声明:
@Bean(name = "orders")
public DefaultWsdl11Definition defaultWsdl11Definition() {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("PedidosPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://www.oracle.com/retail/igsla/integration/services/XYZFullPublishingService/v1");
wsdl11Definition.setSchemaCollection(schemaCollection());
wsdl11Definition.setRequestSuffix("Desc");
wsdl11Definition.setResponseSuffix("Desc");
return wsdl11Definition;
}
private XsdSchemaCollection schemaCollection() {
return new XsdSchemaCollection() {
public XsdSchema[] getXsdSchemas() {
return new XsdSchema[]{new SimpleXsdSchema(new ClassPathResource("orders.xsd")), new SimpleXsdSchema(new ClassPathResource("po.xsd"))};
}
public XmlValidator createValidator() {
throw new UnsupportedOperationException();
}
};
}XSD。orders.xsd:
<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:po="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
targetNamespace="http://www.oracle.com/retail/abcd/integration/services/XYZFullPublishingService/v1"
elementFormDefault="qualified">
<s:import schemaLocation="po.xsd"
namespace="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1" />
<s:element name="publishXYZFullModifyUsingXYZFullDesc">
<s:complexType>
<s:sequence>
<s:element ref="po:XYZFullDesc"/>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>po.xsd:
<?xml version="1.0" encoding="utf-16" ?>
<s:schema targetNamespace="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1"
elementFormDefault="qualified">
<s:element name="XYZFullDesc" type="XYZFullDesc"/>
<s:complexType name="XYZFullDesc">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="order_no" type="s:string"/>
</s:sequence>
</s:complexType>
</s:schema>发布于 2019-01-11 11:56:45
我不知道为什么,但是在将SchemaCollection更改为使用CommonsXsdSchemaCollection之后,错误消失了:
@Bean
public XsdSchemaCollection schemaCollection() {
CommonsXsdSchemaCollection commonsXsdSchemaCollection = new CommonsXsdSchemaCollection(
new ClassPathResource("xsd/po.xsd"),
new ClassPathResource("xsd/orders.xsd"));
commonsXsdSchemaCollection.setInline(true);
return commonsXsdSchemaCollection;
}另外,XSD的顺序在这里注册。如果在嵌套XSD (orders.xsd)之前将父XSD ( ClassPathResource )声明为ClassPathResource,则会收到一些有关“重复命名空间”的错误。
我还需要在XML上添加这个依赖项:
<dependency>
<groupId>org.apache.ws.xmlschema</groupId>
<artifactId>xmlschema-core</artifactId>
<version>2.2.4</version>
</dependency>以防止使用CommonsXsdSchemaCollection产生的“未找到类”的错误。
https://stackoverflow.com/questions/54146087
复制相似问题