Last updated Jul 8, 2024

How do I get a reference to a component?

Confluence 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 a Struts action), the easiest way to access a component is to use constructor injection.

For example, if you need a SpaceManager, you can inject it as follows:

  1. Mark class with @javax.inject.Named or @org.springframework.stereotype.Component annotation and place @Inject or @Autowired respectively;
  2. Mark your field with @ConfluenceImport annotation to let the scanner know that it requires to import it from Confluence;
public class ExampleClass {

    private SpaceManager spaceManager;

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

You can do above points in any order.

Non-Autowired Objects

If your object is not being autowired, you may need to retrieve the component explicitly. This is done using the ContainerManager. For example:

SpaceManager spaceManager = (SpaceManager) ContainerManager.getComponent("spaceManager");

Rate this page: