Search code examples
javaspringdependency-injectionjax-ws

Why is there only one '@Qualifier' annotation in my Spring + jax-ws web application?


I am currently debugging some code to optimize it and I am facing a puzzling situation :

Basically we are deploying a random web service and we are doing some dependency injection(actually I am taking over an already developped and working app, so I am still discovering the app's structure).

My question is pretty specific to the utilization of Spring AND jax-ws at the same time.

We have two classes : an interface and an implementation of this service which will be our web service. We then put two annotations on top of the description of our implementing class :

@Service("myService") //here we let Spring know that this class is a service called "myService"
@WebService(endPointInterface = "com.mydomain.myService") //we expose this service at the given endpoint

public class MyServiceImplementation implements MyServiceInterface(){

//some code

}

public Interface MyServiceInterface {

//some code

}

Here is my point : somewhere, the implementing class declares a property called otherService, this property's type is "MyServiceInterface" so basically it implements the same interface as MyServiceImplementation :

@Autowired

@Qualifier("myClient")

private MyServiceInterface otherService;

so if we put things back in the context :

@Service("myService")

@WebService(endPointInterface = "com.mydomain.myService")

public class MyServiceImplementation implements MyServiceInterface(){

    @Autowired
    @Qualifier("myClient")
    private MyServiceInterface otherService;

//some code

}

If my understanding is good so far : MyService exposes its endpoint at "com.mydomain.myService" and when it is instantiated by the application, Spring automatically looks for the class associated with the qualifier "myClient" and which implements the interface MyServiceInterface to initiate the property otherService with an instance of that same class (which would be the basic principle of dependency injection right ?)

So following this logic, there should be, somewhere in my code, a class declared like this :

@Qualifier("myClient")

public RandomClass implements MyServiceInterface {
}

But there is not, and upon searching for the string "myClient" in the whole project, the only matching results are as follows :

< jaxws:client id="myClient" serviceClass="com.mydomain.myService"
        address="some_address" />

which is located within the application context of the webApp

So I figured out, maybe the qualifier is referring to this jaxws client but then, this would be silly since this would mean that the service is actually trying to "call himself", wouldn't it?

If you could enlighten me on this, I would greatly appreciate it and hopefully this will show helpful to most of us too. Thank you !


Solution

  • in spring @qualifier goes along with autowiring in order to let spring know which beans you'd like to autowire.

    To define the bean that matches this qualifier, you don't have to use the qualifier annotation, there are several other options:
    - define it's id, like they do here
    - if it's annotation based, use @Bean(name="myClient")