Using Spring Java-based configuration:
@Configuration
public class HelloServiceConfig {
@Bean
@Scope("prototype")
public HelloService helloService(@Value("${webservice.endpoint.address}") String endpointAddress) {
HelloService service = new HelloService();
Hello port = service.getHelloPort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,endpointAddress);
return service;
}
}
@Component
public class BusinessService {
@Autowired
private HelloService hellowService;
...
public void setHelloService(HelloService helloService) {
this.helloService = hellowService;
}
}
Edit
To use this with Spring XML-based configuration you just need to register the HelloServiceConfig as a bean in your Spring context xml file:
<bean class="com.service.HelloServiceConfig.class"/>
<bean id="businessService" class="com.service.BusinessService">
<property name="helloService" ref="helloService"/>
</bean>
Other alternatives for creating web service clients in Spring include using Spring Web Services or Apache CXF. Both options allow defining a JAX-WS client based on wsdl2java using only XML but required additional dependencies.