WebServiceRef injection of CXF jax-ws client
I am trying to have my jax-ws client (using Apache CXF) injected via the @WebServiceRef. I have gone through the following steps:
1. Generated the stubs from the WSDL.
2. Created the following <jaxws:client> entry in my applicationContext.xml on the Interface generated through the WSDL.
3. Inserted an @WebServiceRef annotation to inject the web service.
This isn't working and I am getting an exception saying that the Bean is not of the required type, and that it should be of type javax.xml.ws.Service. What am I doing wrong?
The following is my code snippet.
applicationContext.xml
Code:
<?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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor"/>
<jaxws:client id="myService" serviceClass="mt.com.go.springtest.MyService"
address="http://localhost:8080/MyService" name="myService"/>
<bean class="example.MyClient" name="myClient" />
</beans>
MyClient.java
Code:
public class MyClient
{
@WebServiceRef
MyService myService;
...
Exception stacktrace:
Code:
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myService' must be of type [javax.xml.ws.Service], but was actually of type [$Proxy62]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:348)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
...
Another way to solve this?
I realize you had posted this a while ago but I came accross your post trying to solve the same problem. I think I have found a way to use the @WebServiceRef annotation like you may have wanted to do.
Now my client is a web application running inside JBoss with the JBossWS-CXF web service stack so it is possible it worked for me because something JBoss was doing and not CXF but I thought I'd offer.
What worked for me was to have a combination of the 'createdFromAPI' attribute and a different name of the <jaxws:client> bean.
Code:
<jaxws:client name="{http://billing.webagesolutions.com/}BillingManagerPort" createdFromAPI="true"
serviceClass="com.webagesolutions.billing.client.BillingManager">
The critical thing here is the 'name' attribute is the port name of the endpoint being created in the form "{http://service.target.namespace}PortName". This is from the description of the 'createdFromAPI' attribute in the CXF JAXWS configuration page:
http://cxf.apache.org/docs/jax-ws-configuration.html
Using this it was possible for me to use just the following to get a service reference:
Code:
@WebServiceRef
BillingManagerService bms;
(later in the code)
Code:
BillingManager service = bms.getBillingManagerPort();
Now like I say, because I'm running in a client that is in a JBoss environment it is possible that the thing that does the @WebServiceRef construction is JBoss since in an application server this annotation is supposed to refer to a "managed" service reference. Without a Java EE server environment you might not get this behavior.