cancel
Showing results for 
Search instead for 
Did you mean: 

access to the ApplicationContext of alfresco

nabilblk
Champ in-the-making
Champ in-the-making
I want to access into the repository JCR of alfresco in the start of alfresco server .

I do  this :

in web.xml I add :

   <servlet>
      <servlet-name>SpaceRepository</servlet-name>
      <servlet-class>fr.company.alfresco.servlet.SpaceRepositoryServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>


after that i implement My servlet :


public class SpaceRepositoryServlet extends HttpServlet
{
   final static Logger logger=Logger.getLogger(SpaceRepositoryServlet.class);
    public void init(ServletConfig config) throws ServletException
    {
       
       logger.info("SpaceRepository Engine started begin!! ");
       try{
       createSpace();
       }
       catch (Exception e) {
          logger.error("Creating Space Batch Failed !! ", e);
      }
       logger.info("SpaceRepository Engine started End!! ");
    }
   @Override
   public void destroy() {
       logger.info("SpaceRepository Engine stopped begin!! ");
       
       logger.info("SpaceRepository Engine stopped End!! ");

   }




The code of method createSpace(); is :


   private void createSpace() throws Exception{
       ApplicationContext context = ApplicationContextHelper.getApplicationContext();
       Repository repository = (Repository)context.getBean("JCR.Repository");
                …..
                …..

}

I have an error in the first line :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workflowScheduler' defined in class path resource [alfresco/bootstrap-context.xml]: Cannot resolve reference to bean 'jbpm_template' while setting bean property 'JBPMTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration


Note:
I try also :

ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
and
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());

but no way .

Can you help me to access in to applicationContext of alfresco from an servlet
Thanks
3 REPLIES 3

libraspace
Champ in-the-making
Champ in-the-making
Hi,

I am also getting the same error while trying to get Context from a Servlet can anyone help on this.

mmuthu
Champ in-the-making
Champ in-the-making
Hi,
I am also getting the same error when I try to invoke a workflow. I used the SDK 3.2. Please provide a solution.

Thanks,
Muthu

mrogers
Star Contributor
Star Contributor
If your servlet is within the alfresco war file then you can get the spring context from the Application object.

Look at UploadServlet for one example.

If you are a remote application then you need to use one of the remote APIs for alfresco.