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

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Resource resolver returning null...


Level 2

Hello all,


I have two classes. Class A, is where I am calling a method to Class B (Which contains code that's trying to get the resource resolver).

Code for class B where I am getting the null error:




public class NotifyAdminImpl implements NotifyAdminService

private static final Logger LOGGER = LoggerFactory.getLogger(NotifyAdminImpl.class);

ResourceResolverFactory resolverFactory;

public void notifyAdmin(String location,String exception)
LOGGER.debug("We are inside the notifyAdmin method.");


String timeStamp = DateTimeFormatter.ofPattern("MM_dd_yyyy_HH_mm_ss").format(;

HashMap<String, Object> authInfo = new HashMap<String, Object>();

authInfo.put("user.password",new java.lang.String("randomPassword!LOL").toCharArray());

ResourceResolver resourceResolver = resolverFactory.getResourceResolver(authInfo); // line where it nulls out.

Session session = resourceResolver.adaptTo(Session.class);

Resource res = resourceResolver.getResource("/apps/errorHandle/error");

Node node = res.adaptTo(Node.class);

Calendar c = Calendar.getInstance();


String nodeName = location + timeStamp;

String path = node.getPath();


Node errorNode = node.addNode(nodeName,"nt:unstructured");

errorNode.setProperty("jcr:created", c);

errorNode.setProperty("exception", exception);

errorNode.setProperty("isEmailSent", false);;



catch (Exception e)
e.printStackTrace();"An exception in notifyAdmin method occurred due to: " + e.getMessage(),e);




Class A code snippet of calling this method from Class B that's within my OSGi bundle:

NotifyAdminImpl notify = new NotifyAdminImpl();






6 Replies


Community Advisor

Hi @christopherv662 ,


You can get resource resolver through sub service. All you have to do is -


1. Create a System user and give proper permission.

2. Configure "Apache Sling Service User Mapper Service" for System user and Service mapping.

3. Use below code to get the Resource resolver-


public ResourceResolver getResourceResolver() {
ResourceResolver resourceResolver = null;
try {
Map<String, Object> param = new HashMap<>();
param.put(ResourceResolverFactory.SUBSERVICE, "writeService");
resourceResolver = resolverFactory.getServiceResourceResolver(param);
} catch (Exception e) {
return resourceResolver;


I have explained the step by step process in below video-


Level 2
Hi, I tried this and I am still getting the null. I created the service user and mapped it as you did.


Community Advisor

Hi @christopherv662,


First of all, try to see, why the way suggested by @Ritesh_Mittal is not working for you. Here's another article for your reference -


Secondly, try to use 

ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(null) - If the param is null, the resource resolver returned will generally not be authenticated and only provide minimal privileges
Thirdly, What is class A? Do you have access to Resource/Request in that class, so you can pass resource resolver as a parameter, while calling class B


Employee Advisor

Hi @christopherv662 


Can you try "Apache Sling Service User Mapper Service Amendment" rather than "Apache Sling Service User Mapper Service".



@christopherv662  If you're using OSGi R6 annotations, error is probably  beacuse  @Reference annotation would not wrok as below. Try changing it to @OSGIService

ResourceResolverFactory resolverFactory;