package com.lombardrisk.reform.configuration; import javax.annotation.PostConstruct; import javax.annotation.Resource; import javax.ejb.Singleton; import javax.ejb.Startup; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.SimpleCredentials; /** * This class is used to init modeshape jcr repository,it may take a while to init the jcr repository * */ @Singleton @Startup public class JCRInit { @Resource(mappedName = "java:/jcr/repository") private Repository defaultRepository; @PostConstruct //@TransactionAttribute(TransactionAttributeType.REQUIRED) public void init() throws RepositoryException { SimpleCredentials credentials = new SimpleCredentials("admin", "admin".toCharArray()); Session session = null; try{ session = defaultRepository.login(credentials); }finally{ if (session!=null){ session.logout(); } } } }