title: Is there a way to make mtom + validation work in spring ws?
body: <p>I've been looking for a while and couldn't find any solution to this problem, is there a way to make mtom + validation work in spring ws?</p>
  <pre><code>public class WebServiceConfiguration extends WsConfigurerAdapter {
  
      @Override
      public void addInterceptors(final List&lt;EndpointInterceptor&gt; interceptors) {
          final PayloadValidatingInterceptor validatingInterceptor = new PayloadValidatingInterceptor();
          validatingInterceptor.setValidateRequest(true);
          validatingInterceptor.setXsdSchema(this.schema());
          interceptors.add(validatingInterceptor);
      }
  
      @Bean
      public SaajSoapMessageFactory messageFactory() {
          final SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
          messageFactory.setSoapVersion(SoapVersion.SOAP_12);
          return messageFactory;
      }
  
      @Bean
      public Jaxb2Marshaller marshaller() {
          final Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
          marshaller.setContextPath(&quot;com.link.to.package&quot;);
          marshaller.setMtomEnabled(true);
          marshaller.setProcessExternalEntities(false);
          marshaller.setSupportDtd(false);
          return marshaller;
      }
  
      @Bean
      public MarshallingPayloadMethodProcessor methodProcessor(final Jaxb2Marshaller marshaller) {
          return new MarshallingPayloadMethodProcessor(marshaller, marshaller);
      }
  
      @Bean
      DefaultMethodEndpointAdapter endpointAdapter(final MarshallingPayloadMethodProcessor methodProcessor) {
          final DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter();
          adapter.setMethodArgumentResolvers(Collections.singletonList(methodProcessor));
          adapter.setMethodReturnValueHandlers(Collections.singletonList(methodProcessor));
          return adapter;
      }
  
      @Bean
      public ServletRegistrationBean&lt;?&gt; messageDispatcherServlet(final ApplicationContext applicationContext) {
          final MessageDispatcherServlet servlet = new MessageDispatcherServlet();
          servlet.setApplicationContext(applicationContext);
          servlet.setTransformWsdlLocations(true);
          return new ServletRegistrationBean&lt;&gt;(servlet, &quot;/server/*&quot;, &quot;*.wsdl&quot;);
      }
  
      @Bean
      public DefaultWsdl11Definition serverAPI(final XsdSchema schema) {
          final DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
          wsdl11Definition.setServiceName(&quot;ServiceName&quot;);
          wsdl11Definition.setPortTypeName(&quot;PortName&quot;);
          wsdl11Definition.setLocationUri(&quot;/server/ServiceName);
          wsdl11Definition.setCreateSoap11Binding(false);
          wsdl11Definition.setCreateSoap12Binding(true);
          wsdl11Definition.setTargetNamespace(&quot;http://www.example.com/namespace);
          wsdl11Definition.setSchema(schema);
          return wsdl11Definition;
      }
  
      @Bean
      public XsdSchema schema() {
          return new SimpleXsdSchema(new ClassPathResource(&quot;schema.xsd&quot;));
      }
  }
  </code></pre>
  <p>Everything is working fine when I disable MTOM, but once I enable it I have this error</p>
  <p><code>XML validation error on request: cvc-type.3.1.2: Element 'ns2:file' is a simple type, so it must have no element information item [children].</code></p>
  <p>As I said, with MTOM set to false it works.
  Or if I set it to true and I get rid of the PayloadValidatinInterceptor it works...</p>
  <p>This is a workaround that I've found, but still not work.
  <a href="https://stackoverflow.com/questions/38596474/is-saaj-compatible-with-mtom-xop">Is SAAJ compatible with MTOM + XOP?</a></p>