jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gadbury <gadb...@googlemail.com>
Subject Re: spring-modules-jcr - Implementing Spring-based DAOs without callbacks
Date Wed, 08 Jul 2009 19:41:44 GMT

Sergey Podatelev wrote:
> How do you instantiate your ProviderDAOImpl?
> You have Spring instantiating an instance of JackrabbitDaoImpl (thus
> properly initializing SessionFactory), but does it ever instantiates
> an instance of ProviderDAOImpl?

Hi Sergey.  Thanks for your reply.  I understand what you are saying.  I
have tried the following:



public class ProviderDAOImpl extends JcrDaoSupport
	private static Logger logger = Logger.getLogger(ProviderDAOImpl.class);

	public ProviderDAOImpl()

	public ArrayList<ProviderBean> listProviders()
		Session jcrSession = getSession(true);
		ArrayList<ProviderBean> providers = new ArrayList<ProviderBean>();

			Workspace ws = jcrSession.getWorkspace();
			QueryManager qm = ws.getQueryManager();

			// Specify a query using the XPATH query language
			Query q = qm.createQuery("//provider[@isDeleted!='true']", Query.XPATH);
			QueryResult res = q.execute();

			// Obtain a node iterator
			NodeIterator provs = res.getNodes();

			while (provs.hasNext())
					Node providerNode = provs.nextNode();
					providers.add(	new ProviderBean(providerNode.getUUID(),

		catch (Exception e)
			logger.error(e.getCause(), e);

		return providers;



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="	http://www.springframework.org/schema/beans 

        <!-- Register Annotation-based Post Processing Beans -->
        <context:annotation-config />

        <!-- Creates a session factory based on the respository -->
        <bean id="sessionFactory"
			<property name="repository" ref="repository" />
			<property name="credentials">
				<bean class="javax.jcr.SimpleCredentials">
					<constructor-arg index="0" value="userid" />
					<!-- create the credentials using a bean factory -->
					<constructor-arg index="1">
							<bean factory-bean="password" factory-method="toCharArray" />

        <!-- Create the password to return it as a char[] -->
        <bean id="password" class="java.lang.String">
                <constructor-arg index="0" value="" />

        <!-- Create a JcrTemplate using the session factory -->
        <bean id="jcrTemplate" class="org.springmodules.jcr.JcrTemplate">
                <property name="sessionFactory" ref="sessionFactory" />
                <property name="allowCreate" value="true" />

        <!-- DAO configurations -->
        <bean id="jcrDaoProviderImpl"
			<property name="sessionFactory" ref="sessionFactory" />
			<property name="template" ref="jcrTemplate" />

		<!-- Repository definition -->
        <bean id="repository"
			<property name="configuration" value="classpath:repository.xml" />
			<property name="homeDir" value="file:C:/repository1" />


With the above code, I have removed the previous superclass and now the
ProviderDAOImpl extends directly from the spring-modules-jcr class

I am also instantiating a ProviderDAOImpl Spring bean (id =
jcrDaoProviderImpl), which should inject the template (I'm guessing that I
do not need the second property to inject the sessionFactory into the
ProviderDAOImpl bean as sessionFactory is a member of JcrTemplate and is
already injected in to the jcrTemplate bean...) ?

I still have the same problem.  The code falls over at ProviderDAOImpl call
of getSession(true), reporting that "No sessionFactory specified"
(specifically at the Assert statement in the method doGetSession() of the
class org.springmodules.jcr.SessionFactoryUtils).  When I debug, the first
time the jcrTemplate is injected.  Thereafter, it fails (template == null). 
I instantiate my ProviderDAOImpl from the rest of my application's classes
as follows:

ProviderDAOImpl provDAO = new ProviderDAOImpl();

As I am new to Spring (and really just wanted to use the spring-modules-jcr
lib for simple repository configuration / creation and (Jcr) Session
management), I'm sure I must have missed out something important.

Can the Spring ProviderDAOImpl bean (defined above) use any name as the bean

Should I instantiate ProviderDAOImpl in some other way?

Many thanks for your help.
View this message in context: http://www.nabble.com/spring-modules-jcr---Implementing-Spring-based-DAOs-without-callbacks-tp24289110p24397985.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

View raw message