On Mar 23, 2009, at 12:46 PM, Scott Hernandez wrote: > > And everything is fine, but if I add another Queue (in resin-web.xml) > then I get a problem as I have more than one Queue and it is not > unique for injection. Now, in the examples it shows using > @Named("QueueName") but that annotation cannot be applied to a field > as the example seems to indicate. > > @Named("userUpdates") > private BlockingQueue userUpdateQueue; > > How do I differentiate between the queues in my injection annotations?
The docs are a bit out of date, because the Java Injection spec has changed a bit from the earlier draft. "@Named" is now _only_ for EL naming, not for binding. In this case, you're supposed to create your own @BindingType annotation, @UserUpdates. So you inject it like: @UserUpdates private BlockingQueue userUpdateQueue; And you configure it like: <jms:FileQueue> <Named>userUpdates</Named> <mypkg:UserUpdates xmlns:mypkg="urn:java:com.me.mypkg"/> </jms:FileQueue> (I'd put the xmlns:mypkg at the top in a real config file.) Creating the annotation is a little bit of extra work but has the following advantages: 1. it's "type safe", i.e. the compiler (and Java Injection) can verify the @UserUpdates is a valid @BindingType annotation, e.g. saving you from typos. 2. it's documented by JavaDoc, so you can explain the purpose of the @UserUpdates 3. it fits into IDEs, because IDEs have access to the annotation and to the xmlns of your configuration 4. it gives you a chance to think carefully about the organization of your components, in this case to double check that "UserUpdates" is a logical and self-documenting description of the queue you're using. The UserUpdates annotation is defined like: package com.me.mypkg; import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.inject.BindingType; @BindingType @Target({TYPE,FIELD,METHOD,PARAMETER}) @Retention(RUNTIME) public @interface UserUpdates { } (Resin does have a com.caucho.config.Name for generic things like databases, but that kind of general annotation is discouraged.) -- Scott > > > Thanks in advance, > Scott > > > _______________________________________________ > resin-interest mailing list > resin-interest@caucho.com > http://maillist.caucho.com/mailman/listinfo/resin-interest _______________________________________________ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest