Search code examples
javajcrmagnolia

Better way to get a JCR Session object in my Spring MVC Magnolia module that LifeTimeJCRSessionUtil


I am using the following code to get a JCR Session inside my Magnolia module:

LifeTimeJCRSessionUtil.getSession("magicWorkspace");

I'm not using Guice to do IoC. Is this the best way to get hold of a JCR session in a Magnolia module?


Solution

  • The recommended way is using the static methods on MgnlContext. Like so:

    Session session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE)
    

    In RepositoryConstants you'll find constants for the standard JCR workspaces used in Magnolia.