You are here

Module Components

A ModuleComponent executes code and is tied to a specific Module. It is packed with the rest of the module files in an AMP or JAR.
Information Module Components
Support Status Full Support
Architecture Information Platform Architecture
Description A Alfresco Content Services module, such as an AMP or a JAR, can have tightly coupled components (that is, Java classes) that are part of its implementation. When a module is loaded it will also execute the code for each one of its registered components. One component can depend on another component, so it is possible to set up the required execution order. A component can also be associated with an Alfresco Content Services version range for which it is valid, which means that it will only be invoked if current Alfresco Content Services version is in this version range. By default each one of the components will be executed only once when the module is deployed for the first time.

To implement a module component you first need a repository JAR project, such as the one that is part of All-in-One SDK projects. Then start by implementing the component class as in the following example:

public class DemoComponent extends AbstractModuleComponent {
    Log log = LogFactory.getLog(DemoComponent.class);

    protected void executeInternal() throws Throwable {
        System.out.println("DemoComponent has been executed");
        log.debug("Test debug logging. Number of nodes in Company Home = " + childNodesCount(getCompanyHome()));"This is only for information purposed. Better remove me from the log in Production");

    public int childNodesCount(NodeRef nodeRef) {
        return serviceRegistry.getNodeService().countChildAssocs(nodeRef, true);

    public NodeRef getCompanyHome() {
        return serviceRegistry.getNodeLocatorService().getNode("companyhome", null, null);

All components should extend the org.alfresco.repo.module.AbstractModuleComponent class, it provides a lot of general plumbing so you don't have to do it. For example, it provides defaults for properties such as executeOnceOnly and it provides a serviceRegistry so you can get to the public API. The main method that needs to be implemented is called executeInternal and it should contain the work that needs to be done when this component is executed by the module. There can be other methods in the component that provides services useful to other parts of the module implementation. When the component implementation is done it needs to be registered with the module, this is done with a Spring bean as follows:

<bean id="org.alfresco.tutorial.exampleComponent"
    parent="module.baseComponent" >
  <property name="moduleId" value="${project.artifactId}" />  <!-- See -->
  <property name="name" value="exampleComponent" />
  <property name="description" value="A demonstration component" />
  <property name="sinceVersion" value="2.0" />
  <property name="appliesFromVersion" value="2.0" />

The component Spring bean should extend (have as parent) the module.baseComponent bean, which will have the ServiceRegistry property defined and the init-method defined so it will be automatically registered with the module. The module that the component will be registered with is determined by the moduleId property, which should be set to the module id for the repository AMP or repository JAR. The sinceVersion and appliesFromVersion properties can be used to indicate for what Alfresco Content Services versions this component should be activated.

If you want a component to be executed after another component use the dependsOn property as follows:

<bean id="org.alfresco.tutorial.anotherExampleComponent" 
   <property name="moduleId" value="${project.artifactId}" />  <!-- See -->
   <property name="name" value="anotherExampleComponent" />
   <property name="description" value="Another demonstration component" />
   <property name="sinceVersion" value="2.0" />
   <property name="appliesFromVersion" value="2.0" />
   <property name="dependsOn">
      <ref bean="org.alfresco.tutorial.exampleComponent" />

To execute the component at every server start use the following property:

<property name="executeOnceOnly" value="false" />

There is a special component implementation available out-of-the-box for importing content into the repository. It is called ImporterModuleComponent and you can use it by defining the a Spring bean like this:

<bean id="module.test.importerComponent" 
   <property name="moduleId" value="my-module-id" />
   <property name="name" value="MyBootstrapModule" />
   <property name="description" value="My Modules initial data requirements" />
   <property name="sinceVersion" value="1.0" />
   <property name="appliesFromVersion" value="1.0" />
   <property name="appliesToVersion" value="1.4" />
   <property name="importer" ref="spacesBootstrap" />
   <property name="bootstrapViews">
         <prop key="path">/${spaces.company_home.childname}</prop>
         <prop key="location">alfresco/module/myModule-123/myACP.acp</prop>

You can define multiple importer components as your module incrementally evolves. And each one of these importer components can be tied to a specific version of the module. The appliesFromVersion and the appliesToVersion properties are used to filter which module components are allowed to be executed for a specific version of an extension module.

For more information about bootstrapping content see this extension point.

Deployment - App Server
  • tomcat/shared/classes/alfresco/extension/some-context.xml - Define your component Spring beans here (Untouched by re-deployments and upgrades)
  • Note. when developing Java components you are better off using a proper SDK project, see next.
Deployment All-in-One SDK project.
  • aio/platform-jar/src/main/java/{custom package path} - implementation of module components
  • aio/platform-jar/src/main/resources/alfresco/module/platform-jar/context/service-context.xml - Component Spring Bean definitions
More Information
Sample Code

Sending feedback to the Alfresco documentation team

You don't appear to have JavaScript enabled in your browser. With JavaScript enabled, you can provide feedback to us using our simple form. Here are some instructions on how to enable JavaScript in your web browser.