Sometimes we need a session to work with some special JCR API which we can,t use with the help of resourceResolver then we can create an instance of a session in the same class file using the object of resourceResolver. Below is the code snippet.
First, we need to inject the ResourceResolverFactory interface to create a new resourceResolver in AEM. You could inject using the SCR annotation @Reference or Sling Model annotation @Inject.
First, we need to inject the ResourceResolverFactory interface to create a new resourceResolver in AEM. You could inject using the SCR annotation @Reference or Sling Model annotation @Inject.
@ReferenceNow create the ResourceResolver object using resourceResolverFactory. This line of code will create a rsourceResolver with administrator login.
private ResourceResolverFactory resolverFactory;
ResourceResolver resourceResolver=resolverFactory.getServiceResourceResolver(null);Now will create the instance of Session using the object of resourceResolver.
Session session = resourceResolver.adaptTo(Session.class);
No comments:
Post a Comment