|
From: Alef A. <al...@jt...> - 2004-03-02 23:55:38
|
The order is as follows: 1. setting of bean properties (so, including your DAO) 2. BeanNameAware 3. BeanFactoryAware 4. beanpostprocessor - preInitialize 5. afterPropertiesSet 6. init-method 7. beanpostprocessor - postInitialize 8. next bean ((( This should be added to the docs by the way, I'll try to write a = decent piece about it as soon as I have time and also after this discussion ))) This means you're indeed you're going to run into problems there. I've checked the BeanFactory and somewhere it states that (before step 1) it guarantees that all beans the current bean depends on are guaranteed to = be initialized (of which I don't understand how that could be possible = because we're talking circular here). So I guess we'll have to call in the = expert here ;-). J=FCrgen, could you elaborate a bit more here... Alef p.s. if you need a solution ASAP, I suggest you use a BeanFactoryPostProcessor for now (just add one to your application = context, doing some initialization work, it'll get detected automatically, or - = in case you're using just the BeanFactory, apply it programmatically). > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...] On = Behalf > Of James Cook > Sent: Tuesday, March 02, 2004 9:23 PM > To: spr...@li... > Subject: [Springframework-developer] Lifecycle methods >=20 > I think I am missing some basic lifecycle method, but I have read the = docs > and maybe it does not exist? >=20 > I have a cyclic relationship between two beans: >=20 > <bean id=3D"CategoryDAO" class=3D"my.CategoryDAOHibernate"> > <property name=3D"sessionFactory"> > <ref local=3D"sessionFactory"/> > </property> > <property name=3D"categoryHierarchy"> > <ref local=3D"CategoryHierarchy"/> > </property> > </bean> >=20 > <bean id=3D"CategoryHierarchy" class=3D"my.CategoryHierarchy"> > <property name=3D"categoryDAO"> > <ref local=3D"CategoryDAO"/> > </property> > </bean> >=20 > CategoryDAO extends HibernateDaoSupport, so it's afterPropertiesSet() > method > uses the session factory to initialize the DAO which creates a = hibernate > template. >=20 > The CategoryHierarchy is not a database-aware object and it uses the > CategoryDAO object for any data-access it may need. >=20 > The problem is in the afterPropertiesSet() method on the = CategoryHierarchy > object. This is where I decided to make a call to the CateogryDAO and = get > some data that the CategoryHierarchy object needs. Unfortunately, I = get a > NullPointerException because the CategoryDAO object has yet to have = its > afterPropertiesSet method invoked. This method sets up the > HibernateTemplate > object. It is null, thus my NPE. >=20 > Here is the order I am seeing: >=20 > 1. CategoryDAO <init> > 2. CategortHierarchy <init> > 3. CategoryHierarchy.setCategoryDAO(o) > 4. CategoryHierarchy.afterPropertiesSet() > - NPE because it makes a call using CategoryDAO object > 5. CategoryDAO.setSessionFactory(o) > 6. CategoryDAO.setCategoryHierarchy(o) > 7. CategoryDAO.afterPropertiesSet() > - CategoryDAO can only answer calls after this step >=20 > Is there a lifecycle event that fires *after* the factory has = configured > all > of the static beans including all aop bindings? >=20 > I have tried the 'init-method' attribute on the bean. It seems to fire > before afterPropertiesSet. I have tried the BeanFactoryAware = interface, > but > it still fires pretty early. Is there an event that is triggered after = the > factory wires up everything? >=20 >=20 >=20 >=20 > ------------------------------------------------------- > SF.Net is sponsored by: Speed Start Your Linux Apps Now. > Build and deploy apps & Web services for Linux with > a free DVD software kit from IBM. Click Now! > http://ads.osdn.com/?ad_id=3D1356&alloc_id=3D3438&op=3Dclick > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer |