Okay, got it. I will give it a try. Also, this means I can annotate
beans with @Production/@Mock in the xml also, right?

I have a feeling my xmlns declarations section (in resin-web.xml) is
going to be very long. ;(

Maybe I missed it but was there a section in jsr299 dealing with
annotations of beans in xml, or is this resin specific?

Thanks,
Scott
On Tue, Mar 24, 2009 at 9:50 AM, Scott Ferguson <f...@caucho.com> wrote:
>
> 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
>


_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to