When I try to execute a simple JCR call, a java.lang.NullPointerException is thrown.
This is my application-context.xml
And this is my sample code:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- Register Annotation-based Post Processing Beans --> <context:annotation-config /> <!-- <bean id="repository" class="org.springframework.extensions.jcr.jackrabbit.RepositoryFactoryBean"> --> <bean id="repository" class="org.springframework.extensions.jcr.jackrabbit.TransientRepositoryFactoryBean"> <property name="configuration" value="classpath:repository.xml" /> <property name="homeDir" value="file:/tmp/repository" /> </bean> <bean id="sessionFactory" class="org.springframework.extensions.jcr.jackrabbit.JackrabbitSessionFactory"> <property name="repository" ref="repository" /> <property name="credentials"> <bean class="javax.jcr.SimpleCredentials"> <constructor-arg index="0" value="bogus"/> <constructor-arg index="1" value="pass"/> </bean> </property> </bean> <bean id="jcrTemplate" class="org.springframework.extensions.jcr.JcrTemplate"> <property name="sessionFactory" ref="sessionFactory" /> <property name="allowCreate" value="true" /> </bean> </beans>
Code:public class TestServlet extends HttpServlet { private static Logger log = LoggerFactory.getLogger(TestServlet.class); private static final long serialVersionUID = 8388111332983911121L; JcrTemplate template; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try { saveSmth(); } catch (Exception e) { e.printStackTrace(); } try { new conejo().saveBoto(); } catch (Exception e) { e.printStackTrace(); } } public void saveSmth() { template.execute(new JcrCallback() { public Object doInJcr(Session session) throws IOException, RepositoryException { Node root = session.getRootNode(); log.info("starting from root node " + root); Node sample = root.addNode("sample node"); sample.setProperty("sample property", "bla bla"); log.info("saved property " + sample); session.save(); return null; } }); } public class conejo extends JcrDaoSupport { public void saveBoto() throws DataAccessException { Session session = getSession(); try { Node root = session.getRootNode(); log.info("starting from root node " + root); Node sample = root.addNode("sample node"); sample.setProperty("sample property", "bla bla"); log.info("saved property " + sample); session.save(); } catch (RepositoryException ex) { throw convertJcrAccessException(ex); } } } }


Reply With Quote
