views:

34

answers:

2

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?

+1  A: 
@Qualifier("order-url")

and respectively name your component order-url

@Component("order-url")
Bozho
This is what I've actually ended up doing, but it looks less clean that I'd like it to be.
Shooshpanchick
A: 

Of course I don't know all the details, but this issue is more like a task for Decorator pattern. Probably, you may bound this in a Spring config if it's necessary.

Or, I agree with Bozho here, you could use some name conventions across you Spring beans, so that bean name could reflect its responsibility and area of application.

wax
Could you explain how Decorator pattern can be used in this case?
Shooshpanchick