[cdi-dev] Sorting out the "bean name" mess
Bill Shannon
bill.shannon at oracle.com
Thu Sep 6 17:39:36 EDT 2012
Pete Muir wrote on 09/06/2012 02:27 PM:
>> Can I inject a bean by name? That would motivate the more general
>> "bean name".
>
> You can do
>
> @Named("baz")
> public class Foo {}
>
> public class Bar {
>
> @Inject @Named Foo baz;
>
> }
>
> We strongly recommend you don't do it, but you can...
Can I do
@Inject @Named("baz") Foo wombat;
Or, more generally,
@Named("baz")
public class Foo implements Wombat {}
@Named("bletch")
public class Frob implements Wombat {}
public class Bar {
@Inject @Named("baz") Wombat wombat;
}
More information about the cdi-dev
mailing list