Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Getting no class found error with injection of ResourceResolverFactory

Avatar

Level 5

When injecting ResourceResolverFactory into my custom OSGi service I'm gettting a the following exceptions thrown:

*Cannot create component instance due to failure to bind reference repository
*ERROR (org.osgi.framework.ServiceException: Service factory exception: org/apache/sling/api/resource/ResourceResolverFactory)

*com.rogers.services.FolderMonitorService-bundle [com.rogers.services.impl.FolderMonitorServiceImpl(2222)] Failure loooking up method bindResolverFactory(org.osgi.framework.ServiceReference) in class class com.rogers.services.impl.FolderMonitorServiceImpl. Assuming no such method. (java.lang.NoClassDefFoundError: org/apache/sling/api/resource/ResourceResolverFactory)

1 Accepted Solution

Avatar

Correct answer by
Level 10

Using the method described in that article and using the Sling User Mapping service is best practice. 

View solution in original post

10 Replies

Avatar

Correct answer by
Level 10

Using the method described in that article and using the Sling User Mapping service is best practice. 

Avatar

Level 5

The following doesn't seem to exist in the API:

ResourceResolverFactory.SUBSERVICE

resolverFactory.getServiceResourceResolver(param);

while using this dependancy:

        <dependency>
            <groupId>org.apache.sling</groupId>
            <artifactId>org.apache.sling.api</artifactId>
            <version>2.8.0</version>
        </dependency>

Avatar

Level 5

Had to forcefully update dependencies and close/open project to update to 2.8.0

Avatar

Level 5

I'm getting the following exception:

18.01.2017 10:44:04.132 *ERROR* [0:0:0:0:0:0:0:1 [1484754244068] GET /content/fms.html HTTP/1.1] com.day.cq.wcm.core.impl.WCMDebugFilter Error during include of SlingRequestPathInfo: path='/content/fms/jcr:content', selectorString='null', extension='html', suffix='null' org.apache.sling.api.scripting.ScriptEvaluationException:

 

This is how I'm calling it

@Component @Service(Value=SomeClass.class) public class SomeClassImpl implements SomeClass{ @Reference private ResourceResolverFactory resolverFactory; private void someMethod(){ try{ Map<String, Object> param = new HashMap<String, Object>(); param.put(ResourceResolverFactory.SUBSERVICE, "datawrite"); ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(param);; session = resourceResolver.adaptTo(Session.class); } catch (Exception e) { log.info(e.getLocalizedMessage()); } } }

 

I tried restarting the bundles suggested here: https://forums.adobe.com/thread/1117916

And it still didn't work

Avatar

Level 1

I'm getting this to in 6.2 SP1 using the sp1 uber jar. It's looking for the method 'bindResolverFactory()', but we've never had to implement that before 

Full stack is below

18.01.2017 10:57:00.809 *WARN* [OsgiInstallerImpl] com.XXX.aem.aem-sites [com.XXX.aem.integration.pdb.PDBProductCatalogImporterService(2874)] Failure loooking up method bindResolverFactory(org.osgi.framework.ServiceReference) in class class com.XXX.aem.integration.pdb.PDBProductCatalogImporterService. Assuming no such method. (java.lang.NoClassDefFoundError: javax/jcr/version/VersionException)
java.lang.NoClassDefFoundError: javax/jcr/version/VersionException
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethod(Class.java:2128)
    at org.apache.felix.scr.impl.helper.BaseMethod.getMethod(BaseMethod.java:316)
    at org.apache.felix.scr.impl.helper.BindMethod.getServiceReferenceMethod(BindMethod.java:392)
    at org.apache.felix.scr.impl.helper.BindMethod.doFindMethod(BindMethod.java:113)
    at org.apache.felix.scr.impl.helper.BaseMethod.findMethod(BaseMethod.java:171)
    at org.apache.felix.scr.impl.helper.BaseMethod.access$400(BaseMethod.java:37)
    at org.apache.felix.scr.impl.helper.BaseMethod$NotResolved.resolve(BaseMethod.java:558)
    at org.apache.felix.scr.impl.helper.BaseMethod$NotResolved.methodExists(BaseMethod.java:580)
    at org.apache.felix.scr.impl.helper.BaseMethod.methodExists(BaseMethod.java:513)
    at org.apache.felix.scr.impl.helper.BindMethod.getServiceObject(BindMethod.java:643)
    at org.apache.felix.scr.impl.manager.DependencyManager.getServiceObject(DependencyManager.java:2137)
    at org.apache.felix.scr.impl.manager.DependencyManager$SingleStaticCustomizer.prebind(DependencyManager.java:1048)
    at org.apache.felix.scr.impl.manager.DependencyManager.prebind(DependencyManager.java:1457)
    at org.apache.felix.scr.impl.manager.AbstractComponentManager.collectDependencies(AbstractComponentManager.java:983)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getServiceInternal(SingleComponentManager.java:812)
    at org.apache.felix.scr.impl.manager.SingleComponentManager.getService(SingleComponentManager.java:774)
    ... Omitting some for post length contraints
Caused by: java.lang.ClassNotFoundException: javax.jcr.version.VersionException not found by com.XXX.aem.aem-sites [473]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 115 common frames omitted

Avatar

Level 10

I just test this article on 6.2 - it worked perfectly for me: 

Ram Raja- send me an email - we will open a connect session to get to the bottom of this. 

Avatar

Level 1

My issue is resolved now. Was an import that was valid in the IDE, but not when deployed.