Getting session has been close method whenever invoking any event object method



Hi There,


I am getting an error called "this session has been closed " while accessing getNodes() method in event listener using jcr session object. Before executing the below block of code session is coming properly. But whenever i tried to access anything from jcr it is closing the session.

Could you please help what can be the possible reason for this ?

jcrContentNode = getJCRContentNode(event.getProperty(SlingConstants.PROPERTY_PATH).toString());

/*after event.getProperty(...) execution session is getting null values under sd and session context */

private Node getJCRContentNode(String nodePath) throws PathNotFoundException, RepositoryException {
logger.debug("NODE PATH : {}",nodePath);
Node node = jcrSession.getNode(nodePath);
return node;

Accepted Solutions (1)

Accepted Solutions (1)





It looks like you are having trouble accessing the Session object. It's best practice to use "service users" while trying to obtain the Session object as you can define limitations of access within the JCR.

A great example of how to implement Sling event handlers in AEM, while utilising "service users" to obtain a Session object can be found in this blog.

Follow this blog article to learn how to create system users; learning the manual process is best when you are new to "system users" -

Utilise ACS Commons - Ensure Authorize feature to automate the creation of "system users" via OSGI configurations (

Note: It is not recommended to obtain the session with SlingRepository.loginAdministrative() and ResourceResolverFactory.getAdministrativeResourceResolver() methods provided by Sling because of bad design and performance implementations (documentation: Rather, aim for "service users".

Answers (0)