SOAP
WebServiceTemplate
ErrorHandling
Java
SpringFramework

Consuming a SOAP web service error No marshaller registered. Check configuration of WebServiceTemplate

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The error No marshaller registered. Check configuration of WebServiceTemplate means Spring Web Services is trying to send or receive Java objects through WebServiceTemplate, but the template has no configured marshaller and unmarshaller. In other words, Spring knows you want object-to-XML conversion, but it has not been told how to do that conversion.

Why the Error Happens

WebServiceTemplate can work in different modes. If you use methods such as marshalSendAndReceive, Spring expects a marshaller to turn your request object into SOAP XML and an unmarshaller to turn the response XML back into Java objects.

If those components are missing, the template cannot serialize the request payload, so it fails fast with the error you are seeing.

The usual fix is to configure a Jaxb2Marshaller and attach it to the template.

A Typical JAXB-Based Configuration

java
1import org.springframework.context.annotation.Bean;
2import org.springframework.context.annotation.Configuration;
3import org.springframework.oxm.jaxb.Jaxb2Marshaller;
4import org.springframework.ws.client.core.WebServiceTemplate;
5
6@Configuration
7public class SoapClientConfig {
8
9    @Bean
10    public Jaxb2Marshaller marshaller() {
11        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
12        marshaller.setContextPath("com.example.soap.generated");
13        return marshaller;
14    }
15
16    @Bean
17    public WebServiceTemplate webServiceTemplate(Jaxb2Marshaller marshaller) {
18        WebServiceTemplate template = new WebServiceTemplate();
19        template.setDefaultUri("https://example.com/soap");
20        template.setMarshaller(marshaller);
21        template.setUnmarshaller(marshaller);
22        return template;
23    }
24}

The contextPath should point to the package containing the JAXB-generated request and response classes, typically created from the WSDL.

Using the Template Correctly

Once the marshaller is registered, object-based calls work as expected.

java
1MyRequest request = new MyRequest();
2request.setCustomerId("123");
3
4MyResponse response = (MyResponse) webServiceTemplate.marshalSendAndReceive(request);
5System.out.println(response.getStatus());

This pattern only works when the request and response objects are compatible with your configured marshaller.

Another Way to Configure JAXB

Instead of contextPath, you can bind specific classes explicitly.

java
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setClassesToBeBound(MyRequest.class, MyResponse.class);

This is useful when the generated classes are small in number or you want tighter control over exactly what gets bound.

When You Do Not Need a Marshaller

Not every SOAP client call needs object marshalling. If you are sending raw XML sources manually, the marshaller may not be part of the path at all.

For example, if you use lower-level APIs that work with Source, DOM, or StringResult, the template is not trying to convert Java objects automatically.

That distinction matters. The error appears specifically when you call the object-marshalling path without the needed object-XML mapper.

Other Common Causes

Even after adding a marshaller, you can still have configuration problems if:

  • the JAXB classes were not generated correctly from the WSDL
  • the contextPath points to the wrong package
  • only the marshaller was set and the unmarshaller was forgotten
  • the request object is not one of the classes the marshaller knows how to serialize

So the fix is not only "add any marshaller." It is "add the correct marshaller for the classes you are actually sending and receiving."

Common Pitfalls

The most common mistake is calling marshalSendAndReceive without configuring both marshaller and unmarshaller.

Another mistake is pointing Jaxb2Marshaller at the wrong package, so it starts successfully but cannot marshal the actual payload classes.

A third pitfall is mixing raw XML usage and object-based usage without noticing that they require different WebServiceTemplate expectations.

Summary

  • The error means WebServiceTemplate was asked to marshal Java objects without a configured marshaller.
  • The usual fix is to create a Jaxb2Marshaller and register it as both marshaller and unmarshaller.
  • 'contextPath or classesToBeBound must match the SOAP payload classes you actually use.'
  • Object-based calls such as marshalSendAndReceive need marshalling support.
  • If you are sending raw XML instead of Java objects, the marshaller may not be part of the code path.

Related reading
Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions