Piotr Niewinski
Piotr Niewinski

Reputation: 1347

Is there any point of using CDI @Named CDI without any value?

Is there any point of using CDI @Named without a value? Isn't it then simply equivalent of using @Qualifier and @Default together?

@Named
public class GifFileEditor implements ImageFileEditor {

Upvotes: 2

Views: 942

Answers (1)

Laird Nelson
Laird Nelson

Reputation: 16174

If I remember right, @Named with no value element value, when applied to a managed bean, does three things:

  1. It applies the @Named qualifier with an effective value of the simple class name.
  2. It sets the beanName of the bean in question to the simple class name.
  3. It (is the one qualifier that) does not cause the implicit @Default qualifier to be removed.

Now, if you apply it programmatically using, for example, BeanConfigurator#addBean, then you are in charge of deciding which of these behaviors to implement yourself.

Upvotes: 3

Related Questions