cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get AppContext for my Action

7joeblack8
Champ in-the-making
Champ in-the-making
Hi there,


i'm trying to work with the NodeRef of my custom action derived from the simple Logger Custom Action in Alfresco SVN.

Accordingly from what's written here:

http://wiki.alfresco.com/wiki/NodeRef_cookbook

i made something like:

<javascript>…
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
    {          // Attributes
//         beanFactory =  ApplicationContextHelper.getApplicationContext();
//
//         ServiceRegistry serviceRegistry = (ServiceRegistry) beanFactory.getBean(ServiceRegistry.SERVICE_REGISTRY);
        ApplicationContext appContext = new ClassPathXmlApplicationContext("alfresco/application-context.xml");
       
         ServiceRegistry serviceRegistry = (ServiceRegistry) appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
          NodeService nodeService = serviceRegistry.getNodeService();
//          ContentService contentService = serviceRegistry.getContentService();
//         FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
        
        // Get the log message parameter
        String logMessage = "";

           List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef);
            for (ChildAssociationRef childAssoc : children) {
                NodeRef childNodeRef = childAssoc.getChildRef();
                // Use childNodeRef here.
                logMessage = childNodeRef.toString();
            }
           logMessage = logMessage +  " " + actionedUponNodeRef.toString(); //+ " " + (String) nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME);
  
        …</javascript>


As you can see i tryied different ways to get the app context but if i launch my action Alfresco gaves me:
<javascript>Failed to run Actions due to error: Error creating bean with name 'checkOutCheckInServiceHandler' defined in file [/opt/alfresco-4.2.c/tomcat/webapps/alfresco/WEB-INF/classes/alfresco/module/org.alfresco.module.vti/context/vti-handler-context.xml]: Cannot resolve reference to bean 'webDAVLockService' while setting bean property 'webDAVLockService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'webDAVLockService' is defined</javascript>

where is my fault? those beans and that context file sounds strange…

thanks
2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Hello,

please don't try to get the application context in that manner within an Action. There is absolutely no need to - you can inject all the services you require by providing a field, a setter and the necessary "<property>" definition in the Spring context file. Have a look at <a href="http://wiki.alfresco.com/wiki/Custom_Actions#Configuring_in_Spring">the Custom Actions wiki page</a>. The problem you are having should solve itself this way - the problem is, that you are essentially trying to start a new Alfresco Repository within an already running instance.

Regards
Axel

7joeblack8
Champ in-the-making
Champ in-the-making
..well..while i was re-reading the action page wiki i noticed that i didn't update the custom action and so i noticed the same thing you said , anyway thanks!

EDIT:

did it!

thanks Faust!