Adding EJB Annotation Tags

Annotation-based programming tags are used within your EJBs as providers of metadata that is then used to generate other application artifacts as required. You add these tags to your code in the same way that you add Javadoc comments.

About this task

Adding class-level annotations can be done using the Create an Enterprise Bean page.

Procedure

You can automatically generate an annotated bean class using the Create an Enterprise Bean page. Select Generate an annotated bean class, and it creates a default annotated bean class for you.

The code for the annotated bean class is as follows:

Annotated class code

Example

This default annotated bean class illustrates the three basic parts of annotation-based programming:
  • The first element is the phrase * Bean implementation class for Session Bean: MyBean

    This phrase represents the source code comment explaining the function or purpose of this class.

  • The second element includes the asterisk and @ symbol: * @

    The "@" sign indicates that what follows is an annotation that needs to be processed.

  • The third element is the body of the annotation tag:
    * @ejb.bean
    *  name="myBean"
    *  type="Stateless"
    *  jndi-name="ejb/ejbs/MyBeanHome"
    *  local-jndi-name="ejb/ejbs/MyBeanHome"
    *  view-type="both"
    *  transaction-type="Container"
    *

    This code contains the annotations that is used to generate additional artifacts. In this case, the annotation specifies that it is of the ejb.bean type, which defines data relating to Enterprise Java™ Beans. The tag also specifies values for the parameters name, type, jndi-name, local-jndi-name, view-type, and transaction-type.

What to do next

The artifacts specified by the annotation tags are generated at runtime.

Related Reference


Feedback