为什么我的 Spring + jax-ws Web 应用程序中只有一个“@Qualifier”注解?

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

我目前正在调试一些代码来优化它,但我遇到了一个令人费解的情况:

基本上我们正在部署一个随机网络服务并且我们正在做一些依赖注入(实际上我正在接管一个已经开发和工作的应用程序,所以我仍在发现应用程序的结构)。

我的问题非常具体地针对同时使用 Spring 和 jax-ws。

我们有两个 classes :一个接口和一个该服务的实现,这将是我们的网络服务。然后我们将两个注释放在我们实现 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

}

这是我的观点:在某个地方,实现 class 声明了一个名为 otherService 的 属性,这个 属性 的类型是 "MyServiceInterface" 所以基本上它实现了相同的作为 MyServiceImplementation 的接口:

@Autowired

@Qualifier("myClient")

private MyServiceInterface otherService;

所以如果我们把事情放回到上下文中:

@Service("myService")

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

public class MyServiceImplementation implements MyServiceInterface(){

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

//some code

}

如果到目前为止我的理解是好的:MyService 在 "com.mydomain.myService" 处公开其端点,当它被应用程序实例化时,Spring 会自动查找与限定符关联的 class "myClient" 并实现接口 MyServiceInterface 以启动 属性 otherService 与相同 class 的实例(这将是依赖注入的基本原则吧?)

所以按照这个逻辑,在我的代码中应该有一个 class 声明如下:

@Qualifier("myClient")

public RandomClass implements MyServiceInterface {
}

但是没有,在整个项目中查找字符串"myClient",唯一匹配的结果如下:

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

它位于 webApp 的应用程序上下文中

所以我想通了,也许限定符指的是这个 jaxws 客户端,但是,这很愚蠢,因为这意味着该服务实际上正在尝试 "call himself",不是吗?

如果您能就此启发我,我将不胜感激,希望这对我们大多数人也有帮助。谢谢!

in spring @qualifier 与自动装配一起进行,以便让 spring 知道您想要自动装配哪些 bean。

要定义匹配这个限定符的bean,你不必使用限定符注释,还有其他几个选项:
- 定义它的 ID,就像他们在这里做的那样
- 如果它是基于注释的,请使用 @Bean(name="myClient")