How do I get a reference to a component?

How do I get a reference to a component?

Confluence's component system is powered by Spring, but we've done a lot of nice things to make it easier for developers to get their hands on a component at any time.

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 need a SpaceManager simply add the following setter method. This setter will be called when the object is created.

public void setSpaceManager(SpaceManager spaceManager)
{
    this.spaceManager = spaceManager;
}

You can also write you own components which are automatically injected into your plugins in the same way. See Component Plugins for more detail

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:

SpaceManager spaceManager = (SpaceManager) ContainerManager.getComponent("spaceManager");
Was this page helpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport