Calling an operation from an event listener: how to inject dependencies ?


I need to call the “ExportStructureToFS” operation from an event listener in order to trigger a scheduled export mys documents.

I found this explanation about how to call operations from java code, but I can't get the AutomationService and OperationContext injected as suggested in the example.

I use this declarations:

protected AutomationService service;

protected OperationContext context;

Both service and context end being set to null using this technique.

What's wrong ?


0 votes

1 answers




As I understood, those service and context are inside your custom operation "ExportStructureToFS".

Could you check if @Context is org.nuxeo.ecm.automation.core.annotations.Context?

If it is, can you communicate this operation and the contribution xml?

Thank you



I'm using this ready made operation

I can get the descriptor with a get.

Dependency injection is used inside my event listener as follow:

import org.nuxeo.ecm.automation.AutomationService; import org.nuxeo.ecm.automation.OperationContext; import org.nuxeo.ecm.automation.core.annotations.Context;

public class FsExportListener implements EventListener {

private Log logger = LogFactory.getLog(FsExportListener.class);

protected AutomationService service;

protected OperationContext context;

private static final String FS_TARGET = "/home/nuxeo/exports";

private static final String[] ROOTS = { "/default-domain/workspaces/foo/bar/" };

public void handleEvent(Event event) throws ClientException {
    logger.debug("Handling an event...");
    logger.debug("Automation context: " + context); // null
    logger.debug("Automation service: " + service); // null
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("File System Target", FS_TARGET);
    for (String root : ROOTS) {
        logger.debug("Root: " + root);
        parameters.put("Root Name", root);
        try {
  , "ExportStructureToFS", parameters);
        } catch (OperationException e) {
            logger.error("Operation exception");
        } catch (Exception e) {


Maybe I'm wrong ? Thanks btw

edit: I did not post the listener contrib, because the log file is recording debug but let me know if it's needed


I've just read about the @context annotation and it seems to precisely be out of context here. If i'm right dependency injection is not available in this case except for unit testing.

I've just found this link

So I will bet on using the event context and call the service with



Dependency injection via the @context annotation works calling one operation from another.

In that case using:

AutomationService automationService = Framework.getService(AutomationService.class);

To get the service implementation

And OperationContext(), "ExportStructureToFS", parameters);

Solved my problem

0 votes