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.

Annotation-based programming tags form part of an Enterprise Application Project.
  1. Adding class-level annotations can be done using the New EJB Project wizard. On the New EJB Project page, click the Show Advanced >> push button. Select the Add support for annotated Java classes check box.



  2. You can automatically generate an annotated bean class using the Create an Enterprise Bean wizard. Select the Generate an annotated bean class check box, and it will create a default annotated bean class for you. The code for the annotated bean class is as follows:



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 will be 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.

The artifacts specified by the annotation tags will be generated at runtime.

Related Reference

Terms of use | Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.