The org.springbyexample.ws.service package is scanned for beans and will find the PersonServiceClient and inject
the WebServiceTemplate into it. The JAXB marshaller/umarshaller is defined and set on the template.
The import of the jetty-context.xml isn't relevant to creating a client, but it creates an embedded jetty instance that loads the spring-ws-context.xml and it's services. Then client in the unit test is able to run in isolation.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="jetty-context.xml"/>
<context:component-scan base-package="org.springbyexample.ws.client" />
<context:property-placeholder location="org/springbyexample/ws/client/ws.properties"/>
<bean id="personWsTemplate" class="org.springframework.ws.client.core.WebServiceTemplate"
p:defaultUri="http://${ws.host}:${ws.port}/${ws.context.path}/personService/"
p:marshaller-ref="marshaller"
p:unmarshaller-ref="marshaller" />
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="org.springbyexample.person.schema.beans" />
</beans>
Example 3. PersonServiceClient
At this point Spring Web Services handle almost everything. The template just needs to be called and it will return
the PersonResponse from the service endpoint. The client can be used like this:
PersonResponse response = client.getPersons(new GetPersonsRequest());
public class PersonServiceClient implements MarshallingPersonService {
@Autowired
private WebServiceTemplate wsTemplate;
/**
* Gets person list.
*/
public PersonResponse getPersons(GetPersonsRequest request) {
PersonResponse response =
(PersonResponse) wsTemplate.marshalSendAndReceive(request);
return response;
}
}