|
From: Dmitriy K. <dko...@ru...> - 2004-03-03 00:32:07
|
I just want to add - before step 1 (instantiation of any beans) - BeanFac= toryPostProcessor=2EpostProcessBeanFactory(ConfigurableListableBeanFactor= y beanFactory) =22kicks in=22=2E So with the custom implemetation of the = post processor it might be quite possible to eager-initialize concerned b= eans (dao impl in this case) before any other beans in the BeanFactory=2E= Any thoughts on this=3F Regards=2C Dmitriy=2E ----- Original Message ----- From=3A Alef Arendsen =3Calef=40jteam=2Enl=3E Date=3A Tuesday=2C March 2=2C 2004 6=3A43 pm Subject=3A RE=3A =5BSpringframework-developer=5D Lifecycle methods =3E The order is as follows=3A =3E = =3E 1=2E setting of bean properties (so=2C including your DAO) =3E 2=2E BeanNameAware =3E 3=2E BeanFactoryAware =3E 4=2E beanpostprocessor - preInitialize =3E 5=2E afterPropertiesSet =3E 6=2E init-method =3E 7=2E beanpostprocessor - postInitialize =3E 8=2E next bean =3E = =3E ((( This should be added to the docs by the way=2C I=27ll try to writ= e = =3E a decent =3E piece about it as soon as I have time and also after this = =3E discussion ))) =3E = =3E This means you=27re indeed you=27re going to run into problems there=2E= I=27ve =3E checked the BeanFactory and somewhere it states that (before step = =3E 1) it =3E guarantees that all beans the current bean depends on are = =3E guaranteed to be =3E initialized (of which I don=27t understand how that could be = =3E possible because =3E we=27re talking circular here)=2E So I guess we=27ll have to call in = the = =3E experthere =3B-)=2E =3E = =3E J=C3=BCrgen=2C could you elaborate a bit more here=2E=2E=2E =3E = =3E Alef =3E = =3E p=2Es=2E if you need a solution ASAP=2C I suggest you use a =3E BeanFactoryPostProcessor for now (just add one to your application = =3E context=2Cdoing some initialization work=2C it=27ll get detected = =3E automatically=2C or - in =3E case you=27re using just the BeanFactory=2C apply it programmatically= )=2E =3E = =3E =3E -----Original Message----- =3E =3E From=3A springframework-developer-admin=40lists=2Esourceforge=2En= et =3E =3E =5Bspringframework-developer-admin=40lists=2Esourceforge=2Enet=5D= On Behalf =3E =3E Of James Cook =3E =3E Sent=3A Tuesday=2C March 02=2C 2004 9=3A23 PM =3E =3E To=3A springframework-developer=40lists=2Esourceforge=2Enet =3E =3E Subject=3A =5BSpringframework-developer=5D Lifecycle methods =3E =3E = =3E =3E I think I am missing some basic lifecycle method=2C but I have = =3E read the docs =3E =3E and maybe it does not exist=3F =3E =3E = =3E =3E I have a cyclic relationship between two beans=3A =3E =3E = =3E =3E =3Cbean id=3D=22CategoryDAO=22 class=3D=22my=2ECategoryDAOHiberna= te=22=3E =3E =3E =3Cproperty name=3D=22sessionFactory=22=3E =3E =3E =3Cref local=3D=22sessionFactory=22/=3E =3E =3E =3C/property=3E =3E =3E =3Cproperty name=3D=22categoryHierarchy=22=3E =3E =3E =3Cref local=3D=22CategoryHierarchy=22/=3E =3E =3E =3C/property=3E =3E =3E =3C/bean=3E =3E =3E = =3E =3E =3Cbean id=3D=22CategoryHierarchy=22 class=3D=22my=2ECategoryHier= archy=22=3E =3E =3E =3Cproperty name=3D=22categoryDAO=22=3E =3E =3E =3Cref local=3D=22CategoryDAO=22/=3E =3E =3E =3C/property=3E =3E =3E =3C/bean=3E =3E =3E = =3E =3E CategoryDAO extends HibernateDaoSupport=2C so it=27s = =3E afterPropertiesSet()=3E method =3E =3E uses the session factory to initialize the DAO which creates a = =3E hibernate=3E template=2E =3E =3E = =3E =3E The CategoryHierarchy is not a database-aware object and it uses = the =3E =3E CategoryDAO object for any data-access it may need=2E =3E =3E = =3E =3E The problem is in the afterPropertiesSet() method on the = =3E CategoryHierarchy=3E object=2E This is where I decided to make a call= = =3E to the CateogryDAO and get =3E =3E some data that the CategoryHierarchy object needs=2E = =3E Unfortunately=2C I get a =3E =3E NullPointerException because the CategoryDAO object has yet to = =3E have its =3E =3E afterPropertiesSet method invoked=2E This method sets up the =3E =3E HibernateTemplate =3E =3E object=2E It is null=2C thus my NPE=2E =3E =3E = =3E =3E Here is the order I am seeing=3A =3E =3E = =3E =3E 1=2E CategoryDAO =3Cinit=3E =3E =3E 2=2E CategortHierarchy =3Cinit=3E =3E =3E 3=2E CategoryHierarchy=2EsetCategoryDAO(o) =3E =3E 4=2E CategoryHierarchy=2EafterPropertiesSet() =3E =3E - NPE because it makes a call using CategoryDAO object =3E =3E 5=2E CategoryDAO=2EsetSessionFactory(o) =3E =3E 6=2E CategoryDAO=2EsetCategoryHierarchy(o) =3E =3E 7=2E CategoryDAO=2EafterPropertiesSet() =3E =3E - CategoryDAO can only answer calls after this step =3E =3E = =3E =3E Is there a lifecycle event that fires *after* the factory has = =3E configured=3E all =3E =3E of the static beans including all aop bindings=3F =3E =3E = =3E =3E I have tried the =27init-method=27 attribute on the bean=2E It se= ems = =3E to fire =3E =3E before afterPropertiesSet=2E I have tried the BeanFactoryAware = =3E interface=2C=3E but =3E =3E it still fires pretty early=2E Is there an event that is triggere= d = =3E after the =3E =3E factory wires up everything=3F =3E =3E = =3E =3E = =3E =3E = =3E =3E = =3E =3E ------------------------------------------------------- =3E =3E SF=2ENet is sponsored by=3A Speed Start Your Linux Apps Now=2E =3E =3E Build and deploy apps =26 Web services for Linux with =3E =3E a free DVD software kit from IBM=2E Click Now! =3E =3E http=3A//ads=2Eosdn=2Ecom/=3Fad=5Fid=3D1356=26alloc=5Fid=3D3438=26= op=3Dclick =3E =3E =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =3E =3E Springframework-developer mailing list =3E =3E Springframework-developer=40lists=2Esourceforge=2Enet =3E =3E https=3A//lists=2Esourceforge=2Enet/lists/listinfo/springframewor= k- =3E developer =3E = =3E = =3E ------------------------------------------------------- =3E SF=2ENet is sponsored by=3A Speed Start Your Linux Apps Now=2E =3E Build and deploy apps =26 Web services for Linux with =3E a free DVD software kit from IBM=2E Click Now! =3E http=3A//ads=2Eosdn=2Ecom/=3Fad=5Fid=1356=26alloc=5Fid438=26op=3Dclic= k =3E =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F =3E Springframework-developer mailing list =3E Springframework-developer=40lists=2Esourceforge=2Enet =3E https=3A//lists=2Esourceforge=2Enet/lists/listinfo/springframework-de= veloper =3E |