How to set username and password when consuming a SOAP service with Spring

By Adrian Smith19 Mar 2019100 words1 mins to read

Spring's Consuming web service guide is great at describing how to go about being a client of a SOAP service, but it doesn't mention how to consume web services which are protected by any sort of security.

In case your service requires a <Security> element in the SOAP header like:


then I have written a small class which can be used in your code thus:

   new SoapClientSecurityHeaderWriter("user", "pw"));

You can include this class with the following lines in Maven:


The source is here: SoapClientSecurityHeaderWriter.

This article was written by Adrian Smith on 19 Mar 2019

Follow me: Facebook | Twitter | LinkedIn | Email

More on: Spring