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.


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.


Optional annotation defining the priority of a GBean.


Annotation defining a GBean special attribute to be injected.


Annotation defining the GBean attribute to be injected.


Annotation defining the GBean reference to be injected.


Annotation for setter methods turning the corresponding GBean attributes into persistent attributes.


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 dployment plan for SimpleServerGBean has to be modified.

<gbean name="echoserver" class="org.apache.geronimo.sample.SimpleServerGBean">
    <attribute name="port">7777</attribute>
    <attribute name="gbeanName">simpleServer</attribute>
    <reference name="EchoMessageInterface">
<gbean name="msgAppender" class="org.apache.geronimo.sample.EchoMessageGBean">
    <attribute name="msg">[Echo from server 1]:</attribute>

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.

public class AuthConfigProviderGBean implements GBeanLifecycle {

    private final String registrationID;

    public AuthConfigProviderGBean(@ParamAttribute(name = "config") String config, 
                                   @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader classLoader) 
    throws AuthException, JAXBException, IOException, ParserConfigurationException, SAXException, XMLStreamException {

        ClassLoaderLookup classLoaderLookup = new ConstantClassLoaderLookup(classLoader);

        String messageLayer = null;
        String appContext = null;

        AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
        ConfigProviderType configProviderType = JaspiXmlUtil.loadConfigProvider(new StringReader(config));
        AuthConfigProvider authConfigProvider = JaspiUtil.wraptAuthConfigProvider(configProviderType, classLoaderLookup);
        registrationID = authConfigFactory.registerConfigProvider(authConfigProvider, messageLayer, appContext, null);

    public void doStart() throws Exception {

    public void doStop() throws Exception {
        AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();

     * Fails the GBean.  This informs the GBean that it is about to transition to the failed state.
    public void doFail() {
public class JmxDiscoveryPublisher implements GBeanLifecycle {

    private final URI service;
    private final DiscoveryAgent discoveryAgent;

    public JmxDiscoveryPublisher(@ParamAttribute(name = "nodeName")String nodeName,
                                 @ParamAttribute(name = "clusterName")String clusterName,
                                 @ParamAttribute(name = "protocol")String protocol,
                                 @ParamAttribute(name = "urlPath")String urlPath,
                                 @ParamAttribute(name = "discoveryType")String discoveryType,
                                 @ParamReference(name = "DiscoveryAgent")DiscoveryAgent discoveryAgent,
                                 @ParamReference(name = "RMIRegistryService")RMIRegistryService rmiRegistryService
    ) throws URISyntaxException, IOException {
        this.discoveryAgent = discoveryAgent;
        String query = null;
        if (nodeName != null && nodeName.length() > 0) {
            query = "node=" + nodeName;
        if (clusterName != null) {
            query = (query == null? "": query + "&") + "cluster=" + clusterName;
        service = new URI(discoveryType + ":" + protocol, null,  rmiRegistryService.getHost(),
                          rmiRegistryService.getPort(), "/" + urlPath , query, null);

    public void doStart() throws Exception {

    public void doStop() throws Exception {

    public void doFail() {
        try {
        } catch (Exception e) {