What can be put in an EJB stereotype?

591 views Asked by At

We're migrating an EJB 3.0 application to EJB 3.1 and would like to use @Stereotype to reduce some of the EJB configuration.

The annotations we plan to have are:

Of those I know that @Singleton can't be put into a @Stereotype and has to be on the EJB itself. What else can't be put into a @Stereotype?

Update

The specification [1], [2] says that

A stereotype encapsulates any combination of:

  • default scope, and
  • a set of interceptor bindings.

The examples then use Java EE 7 @Transactional which is an @InterceptorBinding which leads me to believe that none of the above annotations can be put into a stereotype.

1

There are 1 answers

2
Alexander Rühl On

The The Java EE 6 Tutorial states the following:

A stereotype is a kind of annotation, applied to a bean, that incorporates other annotations. Stereotypes can be particularly useful in large applications where you have a number of beans that perform similar functions. A stereotype is a kind of annotation that specifies the following:

  • A default scope

  • Zero or more interceptor bindings

  • Optionally, a @Named annotation, guaranteeing default EL naming

  • Optionally, an @Alternative annotation, specifying that all beans with this stereotype are alternatives

So as you saw yourself, the annotations you used are not in one of the mentioned groups.

My personal suggestion is, to be careful with creating and using stereotypes, since one then always have to know (or check) what it means, so for example I prefer using @Named @RequestScoped rather than @Model because saving one line of code does not make up to not see the scope at the first glance.