Rate this page:
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.
If your object is being autowired (for example, another plugin module or an XWork 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:
@javax.inject.Named
or @org.springframework.stereotype.Component
annotation and place @Inject
or @Autowired
respectively;@ConfluenceImport
annotation to let the scanner know that it requires to import it from Confluence;1 2 3 4 5 6 7 8 9 10 11
@Named
public class ExampleClass {
@ConfluenceImport
private SpaceManager spaceManager;
@Inject
public void setSpaceManager(SpaceManager spaceManager){
this.spaceManager = spaceManager;
}
}
You can do above points in any order.
If your object is not being autowired, you may need to retrieve the component explicitly. This is done using the ContainerManager
.
For example:
1
SpaceManager spaceManager = (SpaceManager) ContainerManager.getComponent("spaceManager");
Rate this page: