cancel
Showing results for 
Search instead for 
Did you mean: 

How to acess repository using JCR and a Session Bean

pinkman
Champ in-the-making
Champ in-the-making
In a nutshell, I want to connect to an Alfresco repository from a session bean. It will be running on the same JBoss instance as Alfresco (tho that could change in the future).

I would prefer JCR as I am a standards freak, tho I can't get my head around how to connect to a pre-existing repository. The JNDI project http://issues.alfresco.com/browse/AR-1131 looks useful but maybe a little immature? I have a feeling I am going in the wrong direction with it anyway.

I have read the "Simple Example", and understand most things AFTER the repository is accessed, but how it accessed the repository instance is still a bit of a mystery to me. At the end of the day I am just trying to get an instance of a JCR "Repository" object. What is the best way to get started?
13 REPLIES 13

morpheus
Champ in-the-making
Champ in-the-making
ok , let me correct me own things:
i must appreciate, that this was my failure:
because in the test. i  called the context by an complete path as the parameter! But the class ClassPathXmlApplicationContext searches in the class path for the location "classpath + parameter". so it has go wrong!!
but now i got something new.
the following code returns that Exception:
But now ich checked, that jcr-api-context.xml is in the directory,where it should be !
Repository repository = (Repository)context.getBean("JCR.Repository");

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'JCR.Repository' is defined
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:340)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:906)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:642)
   at de.tarent.momeLearnClient.JCRTest.testGettingRepository(JCRTest.java:49)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)

rv_a_sharma
Champ in-the-making
Champ in-the-making
Hello morpheus ,

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'JCR.Repository' is defined

This is the error that I am also getting, how us solved this problem ?

I am trying to run the SimpleExample.java program given by the Alfresco in sample programs.

Regards,
Ravi Sharma

rv_a_sharma
Champ in-the-making
Champ in-the-making
But I don't understand if I am just trying the SampleExample.java file distributed along with the Alfresco content.

Its a plain java file and trying to get the Application context.
I can get it like .
CODE: SELECT ALL

// Setup Spring and Transaction Service
       ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:alfresco/application-context.xml");


Now using this context I want to get he handle on Repository . This is done in the sample code.
But how come its not accepting it . At compile time i have defined that this is going to be the dependency.

But how can i define at the run time that one has to use a class which is available in the package
CODE: SELECT ALL
public class RepositoryImpl implements Repository


I dont understand now what should i do to make this standalone sample java run ?

Regards,
Ravi Sharma