Announcement Announcement Module
No announcement yet.
WebServiceRef injection of CXF jax-ws client Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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 What am I doing wrong?

    The following is my code snippet.


    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
    	<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=""
                      address="http://localhost:8080/MyService" name="myService"/>
      <bean class="example.MyClient" name="myClient" />    
    public class MyClient
      MyService myService;
    Exception stacktrace:
    Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myService' must be of type [], but was actually of type [$Proxy62]

  • #2
    1)At server side:

    Make sure that your service impl and SEI[interface for webservice] both have @WebServicre annotation.

    Assuming that MyService is an SEI and it has @WebService exposed

    its impl also should have:

    @WebService(endpointInterface =")

    2)At Client side:
    try to inject myService in MyClient also.


    • #3
      WebServiceRef annotation

      I am not implementing the server, so it doesn't have anything to do with the server implementation. I just have a WSDL which I am processing into stubs on the client side to use.

      Injection without @WebServiceRef works OK. But that's the whole point. I do not want to manually inject it in every bean that needs the Web service stub and I do not want to insert stuff like @Autowire etc.

      I wish to use the @WebServiceRef annotation client side, so that any bean which refers to the web service client stub gets it through there. This would be fully JAX-WS and JEE compliant.

      The @WebServiceRef is advertised to work in Spring but I can't find a proper example anywhere and trial and error just got me to the above point.


      • #4
        Are you using standalone client?If yes,then you can refer:
        You can refer to:
            public class HelloClient {
            static HelloService service;
            public static void main(String[] args) {
                try {
                    HelloClient client = new HelloClient();
                } catch(Exception e) {
        I see wsdlLocation is missing in your code but thats just my guess that it can be an issue.
        IAnyway,I will try a sample using @WebServiceRef later.
        Last edited by spring2007; Jun 8th, 2010, 10:09 AM.


        • #5
          I want to avoid that because I don't want to hardcode the URL of the WSDL in the annotation.

          I want it to pick it up from the <jaxws:client> configuration which will have everything; endpoint URL, WSDL Location URL (which afaik is optional), username, password etc.


          • #6
            I've never used the @WebServiceRef stuff, but if you read the javadoc for it, it basically says that if you are injecting into a field that is the SEI, you have to specify the "value" attribute that points to the subclass of I don't know if the Spring processing even cares about the Service subclass, but the javadocs say it must be there. You might also want to specify the "type" attribute as well, just to be clear.


            • #7
              Yep tried it too (both with the type and without the type, using both the WebServiceClient class implementing and the Interface). I get a similar error.

              Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'myService' must be of type [], but was actually of type [$Proxy62]
              Is it my impression that this approach with the @WebServiceRef is not that common?
              It is mentioned in specs and J2EE tutorials, but not much more. The advantage to inject it pre-configured by the framework (Spring, Glassfish or whatever) isn't mentioned ever and I haven't found one example anywhere yet.


              • #8
                @Resource works

                By the way, I just discovered that @Resource works cleanly, without any parameter.

                I wonder why @WebServiceRef doesn't work.


                • #9
                  My experience with @Resource vs native Spring autowiring is that native Spring autowiring doesn't like abstract class based injections in stead of interface based injections even though the documentation states that it should work.


                  • #10
                    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.

                    <jaxws:client name="{}BillingManagerPort" createdFromAPI="true"
                    The critical thing here is the 'name' attribute is the port name of the endpoint being created in the form "{}PortName". This is from the description of the 'createdFromAPI' attribute in the CXF JAXWS configuration page:

                    Using this it was possible for me to use just the following to get a service reference:

                    BillingManagerService bms;
                    (later in the 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.