Component plugin modules enable you to add components to Confluence's internal component system (powered by Spring).
Component Plugin ModuleEach 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>
Accessing Your ComponentsAccessing your components is extremely simple. Autowired ObjectsIf 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 ObjectsIf 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");
NotesSome issues to be aware of when developing a component:
|

Comments (6)
Dec 06, 2005
David Peterson [CustomWare] says:
Another note would be that component modules do not unload correctly if they are...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.
Feb 15, 2006
Dan Hardiker says:
If you disable the plugin before uninstalling it, and then enabled it after inst...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.
Feb 15, 2006
David Peterson [CustomWare] says:
Nice find! Looking forward to this one being fixed.Nice find! Looking forward to this one being fixed.
Feb 01, 2008
Anonymous says:
Looking forward to this fix -jake dual action cleanseLooking forward to this fix
-jake
dual action cleanse
Feb 14, 2008
Anonymous says:
What is the scope for these components? On first glance they appear to have app...What is the scope for these components? On first glance they appear to have application scope.
-m
Feb 14, 2008
David Peterson [CustomWare] says:
I believe that is the case, however if you try to access a component published i...I believe that is the case, however if you try to access a component published in one plugin from a different plugin it won't work because the second plugin cannot access classes defined in the first plugin.
Personally, I don't use components at all any more, partly for this reason. For singletons I use standard static classes and methods. If I need to communicate between plugins it gets trickier, but I have a couple of libraries to help there too. Contact me if you have to do that.
Add Comment