title: Multiple XSDs on SchemaCollection: schemaElement must not be null?
body: <p>I'm trying to use the <code>SchemaCollection</code> on my Web Service configuration. But when I added the code for that, I receive this error:</p>
  
  <blockquote>
    <p>Caused by: java.lang.IllegalArgumentException: schemaElement must not be null! Did you run afterPropertiesSet() or register this as a Spring bean?</p>
  </blockquote>
  
  <p>What this error means? Looking on the <a href="https://github.com/spring-projects/spring-ws/blob/master/spring-xml/src/main/java/org/springframework/xml/xsd/SimpleXsdSchema.java" rel="nofollow noreferrer">Spring code</a>, is something related with the <code>schemaElement</code> on the XSD, but I'm not able to say what.</p>
  
  <p>Whitout the schemaCollection, everything works fine.</p>
  
  <p>Full error:</p>
  
  <pre><code>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 omitted
  </code></pre>
  
  <p>The bean declaration:</p>
  
  <pre><code>@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();
              }
          };
      }
  </code></pre>
  
  <p>XSDs. The orders.xsd:</p>
  
  <pre><code>&lt;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"&gt;
  
      &lt;s:import schemaLocation="po.xsd"
                 namespace="http://www.oracle.com/retail/integration/base/bo/XYZFullDesc/v1" /&gt;
  
      &lt;s:element name="publishXYZFullModifyUsingXYZFullDesc"&gt;
          &lt;s:complexType&gt;
              &lt;s:sequence&gt;
                  &lt;s:element ref="po:XYZFullDesc"/&gt;
              &lt;/s:sequence&gt;
          &lt;/s:complexType&gt;
      &lt;/s:element&gt;
  
  &lt;/s:schema&gt;
  </code></pre>
  
  <p>And the po.xsd: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16" ?&gt;
  &lt;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"&gt;
  
      &lt;s:element name="XYZFullDesc" type="XYZFullDesc"/&gt;
  
      &lt;s:complexType name="XYZFullDesc"&gt;
          &lt;s:sequence&gt;
              &lt;s:element minOccurs="0" maxOccurs="1" name="order_no" type="s:string"/&gt;
          &lt;/s:sequence&gt;
      &lt;/s:complexType&gt;
  
  &lt;/s:schema&gt;
  </code></pre>