HomeDocumentation > Reference > Geronimo Architecture > GBeans > GBean Annotations

Definition of annotations streamlines the definition of GBeanInfo. With the help of GBean annotations, you will be freed from adding attributes, operations, and references in GBeanInfo.

Annotations for GBeans are defined as follows, and are defined in the package org.apache.geronimo.gbean.annotation.

@GBean Optional annotation defining the name and j2eeType of a GBean. If this annotation is not specified, then the default name is assumed to be the class (simple) name and the default j2eeType is GBean.
@Priority Optional annotation defining the priority of a GBean.
@ParamSpecial Annotation defining a GBean special attribute to be injected.
@ParamAttribute Annotation defining the GBean attribute to be injected.
@ParamReference Annotation defining the GBean reference to be injected.
@Persistent Annotation for setter methods turning the corresponding GBean attributes into persistent attributes.
@Reference Annotation for setter methods turning the corresponding GBean attribute into a GBean reference.

Note that at most one constructor must be annotated with @ParamSpecial, @ParamAttribute or @ParamReference.

Developing a GBean using Annotations

For developing a GBean with annotations, you at least have to go through the following steps:

  1. Write a POJO class
  2. Implement GbeanLifecycle inteface to use the Gbean Kernel lifecycle callback (Optional).

A sample GBean

Here we rewrite the sample simpleServerGBean provided in Developing and Deploying a Geronimo GBean, which references another GBean named EchoMessageGBean.

  • The SimpleServerGBean refers to another GBean EchoMessageInterface, which is described in Referencing another GBean.
  • The Plain Old Java Object (POJO) code comes with a different constructor annotated with @ParamSpecial, @ParamAttribute or @ParamReference.
  • There is no difference between the LifeCycle code implemented with and without annotations.
  • As the Geronimo kernel will recognize and invoke the attributes, operations, references and constructors defined with annotations, we have removed GBeanInfo implementation.

The dployment plan for SimpleServerGBean has to be modified.

Excerpt from simpleServer_deployment_plan.xml

Note: If you define the j2eeType attribute of the EchoMessageInterface GBean, you have to specify this attribute in the <reference> section of deployment plan so that Geronimo can recognize the GBean.

Further Reference

Two examples extracted from Geronimo source are presented here for your reference.