This page last changed on Jan 17, 2007 by jnolen.
Component plugin modules are available in Confluence 1.4 and later

Component plugin modules enable you to add components to Confluence's internal component system (powered by Spring).

Component Plugin Module

Each component module adds a single object to Confluence's component management system.

Other plugins and objects within Confluence can then be autowired with your component. This is very useful for having a single component that is automatically passed to all of your other plugin modules (ie a Manager object).

Here is an example atlassian-plugin.xml file containing a single component module:

<atlassian-plugin name="Sample Component" key="confluence.extra.component">
    ...
    <component name="Keyed Test Component" 
        key="testComponent" 
        alias="bogusComponent"
        class="com.atlassian.confluence.plugin.descriptor.BogusComponent" />
    ...
</atlassian-plugin>
  • the name attribute represents how this component will be referred to in the interface.
  • the key attribute represents the internal, system name for your component.
  • the class attribute represents the class of the component to be created
  • the alias attribute represents the alias this component will be stored with. This element is optional, if not specified the module key will be used instead.

Accessing Your Components

Accessing your components is extremely simple.

Autowired Objects

If your object is being autowired (for example another plugin module or an XWork action), the easiest way to access a component is to add a basic Java setter method.

For example, if you use the above BogusComponent module your object would retrieve the component as follows:

public void setBogusComponent(BogusComponent bogusComponent)
{
    this.bogusComponent = bogusComponent;
}

Non-autowired Objects

If your object is not being autowired, you may need to retrieve the component explicitly. This is done via the ContainerManager like so:

BogusComponent bc = (BogusComponent) ContainerManager.getComponent("bogusComponent");

Notes

Some issues to be aware of when developing a component:

  • One component module can depend on another component module but be careful of circular references (ie A requires B, B requires A).
  • The component "namespace" is flat at the moment, so choose a sensible alias for your component.

How did you pull off that autowiring giving brand new plugins the ability to access components via injection? Its rather amazing and simplifies things so much. I don't think you get this out of the box with Spring (do you?). How did you pull it off? Any pointers or links?

thanks! Brendan

Posted by bpatters7 at Jul 23, 2005 15:05

Another note would be that component modules do not unload correctly if they are in a plugin which is uploaded rather than being put into WEB-INF/lib. The plugin can be uploaded, but the web server will have to be restarted regardless, making it kind of pointless uploading it in the first place.

See CONF-4014 to track this issue.

Posted by david@randombits.org at Dec 06, 2005 17:55

If you disable the plugin before uninstalling it, and then enabled it after installing it again it all works ok.

Atlassian have been made aware of the issue and where it is likely to lie.

Posted by dhardiker@adaptavist.com at Feb 15, 2006 09:47

Nice find! Looking forward to this one being fixed.

Posted by david@randombits.org at Feb 15, 2006 10:40

Hello! I have a problem adding a Component Module to my plugin. I've got a theme module and an XWork module in the plugin. I try to add the following to my plugin's atlassian-plugin.xml:
<component name="Local Projects Tree"
key="myLocalProjectsTree"
alias="localProjectsTree"
class="com.mystuff.LocalProjectsTree" />

When installing my plugin into Confluence an error occurs:
There was a problem loading the module descriptor: com.mystuff.LocalProjectsTree.
Can not overwrite an existing bean definition: localProjectsTree.

Posted by positive at Nov 14, 2006 09:18

Hello! I have a problem adding a Component Module to my plugin. I've got a theme module and an XWork module in the plugin. I try to add the following to my plugin's atlassian-plugin.xml:
<component name="Local Projects Tree"
key="myLocalProjectsTree"
alias="localProjectsTree"
class="com.mystuff.LocalProjectsTree" />

When installing my plugin into Confluence an error occurs:
There was a problem loading the module descriptor: com.mystuff.LocalProjectsTree.
Can not overwrite an existing bean definition: localProjectsTree.

What do I do wrong?

Posted by positive at Nov 14, 2006 09:19
Document generated by Confluence on Mar 22, 2007 21:00