在Spring中可以使用多个@Qualifier注释吗? [英] Is it possible to use multiple @Qualifier annotation in Spring?
问题描述
我有一组具有两个属性的bean。它们基本上是用于不同类和不同目的的序列化器。
例如,对于本地日志,可能有一个 Order
序列化程序, Order
序列化程序用于记录Web服务调用,客户
序列化程序用于跟踪URL,而客户
序列化程序用于跟踪URL。 / p>
这就是为什么我要使用两个 @Qualifier
批注,如下所示:
@Autowired
@Qualifier( order)
@Qualifier( url)
private Serializer< Order> orderSerializer;
不幸的是,在这种情况下,编译器抱怨重复的注释。有没有解决此问题的方法或替代解决方案?
@Qualifier( order -url)
并分别命名组件 order-url
@Component( order-url)
I have a set of beans that are characterized by two properties. They are basically serializers for different classes and for different purposes.
For example, there may be an Order
serializer for local log, Order
serializer for logging webservice call, Customer
serializer for tracking URL and Customer
serializer for tracking URL.
This is why I'd like to use two @Qualifier
annotations like this:
@Autowired
@Qualifier("order")
@Qualifier("url")
private Serializer<Order> orderSerializer;
Unfortunately, compiler complains about duplicate annotations in this case. Are there any workarounds or alternative solutions to this problem?
@Qualifier("order-url")
and respectively name your component order-url
@Component("order-url")
这篇关于在Spring中可以使用多个@Qualifier注释吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!