Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Stuck trying to use @Reference private ResourceResolverFactory resolverFactory;

Clive_Stewart
Level 6
Level 6

Hi,

I am trying to connect to the CRX repository.

Initially I created a connection in a class inside of Eclipse using

        // Create a connection to the CQ repository running on local host
            Repository repository = JcrUtils
                    .getRepository("http://localhost:4502/crx/server");

            // Create a Session
            javax.jcr.Session session = repository.login(new SimpleCredentials( /
                    "admin", "admin".toCharArray()));

When I imported my class into a CRXDE bundle that I created this did not work. So I read further that the above method does not work in the sling bundle and that I need to use esourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);

        as by http://helpx.adobe.com/experience-manager/using/using-sling-apis.html

 

In this development article, a ResourceResolverFactory instance is injected into the getJCRData method. This instance is required to retrieve a resource from the AEM JCR. To inject a ResourceResolverFactory instance, you use the @Reference annotation to define a class member, as shown in the following example.

//Inject a Sling ResourceResolverFactory
@Reference
private ResourceResolverFactory resolverFactory;

Within the getJCRData method, invoke the ResourceResolverFactoryobject's getAdministrativeResourceResolver method to create a ResourceResolverobject. You can use a ResourceResolver instance to get a resource located in the AEM JCR as shown here.

ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Resource res = resourceResolver.getResource(resourcePath);

 

My problem is that i cannot get @Reference
private ResourceResolverFactory resolverFactory; to resolve. 

 

I understand that it is an interface, but that it was implemented in bundle >> import org.apache.sling.api.resource.*;

 

I imported org.apache.sling.resourceresolver-1.1.0.jar into my build path.

 

What am I missing. 

 

Regards

 

Clive

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
Level 10

See this community article for use on this subject:

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

In this article - the OSGi bundle is built via Maven. 

View solution in original post

1 Reply
smacdonald2008
Correct answer by
Level 10
Level 10

See this community article for use on this subject:

http://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html

In this article - the OSGi bundle is built via Maven. 

View solution in original post