|
From: James C. <jim...@do...> - 2004-03-03 18:26:13
|
I'm seeing strange behavior when I try to use this interface. I have
implemented a class that implements this interface and registered it in =
my
app config.
public class BeanPostProcessorFactory implements =
BeanFactoryPostProcessor {
public void postProcessBeanFactory(ConfigurableListableBeanFactory
beanFactory) throws BeansException {
Map map =3D
beanFactory.getBeansOfType(BeanPostProcessor.class, true, true);
for (Iterator i =3D map.values().iterator(); i.hasNext();) {
BeanPostProcessor bean =3D (BeanPostProcessor)
i.next();
bean.postProcessBean(beanFactory);
}
}
}
So I've created an interface that I can apply to my beans, causing them =
to
be invoked by the BeanFactoryPostProcessor.
What's strange is that this BeanFactoryPostProcessor does not seem to =
fire
when I expected. I expected it to fire *after* the BeanFactory has
instantiated and wired up all of the beans.
But instead, according to the code in AbstractApplicationContext, it =
appears
that this method call is firing before the
getBeanFactory().preInstantiateSingletons() method?
> -----Original Message-----
> From: spr...@li...
> [mailto:spr...@li...] On =
Behalf
> Of Dmitriy Kopylenko
> Sent: Tuesday, March 02, 2004 11:11 PM
> To: spr...@li...
> Subject: Re: RE: [Springframework-developer] Lifecycle methods
>=20
> Alef, oops, didn't see that you already suggested
> BeanFactoryPostProcessor... :-)
>=20
> D.
>=20
> ----- Original Message -----
> From: Dmitriy Kopylenko <dko...@ru...>
> Date: Tuesday, March 2, 2004 7:18 pm
> Subject: Re: RE: [Springframework-developer] Lifecycle methods
>=20
> > I just want to add - before step 1 (instantiation of any beans) -
> >
> =
BeanFactoryPostProcessor.postProcessBeanFactory(ConfigurableListableBeanF=
a
> ctory beanFactory) "kicks in". So with the custom implemetation of the
> post processor it might be quite possible to eager-initialize =
concerned
> beans (dao impl in this case) before any other beans in the =
BeanFactory.
> Any thoughts on this?
> >
> > Regards,
> > Dmitriy.
> >
> > ----- Original Message -----
> > From: Alef Arendsen <al...@jt...>
> > Date: Tuesday, March 2, 2004 6:43 pm
> > Subject: RE: [Springframework-developer] Lifecycle methods
> >
> > > 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
> > > experthere ;-).
> > >
> > > 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...
> > > > [spr...@li...] On =
Behalf
> > > > Of James Cook
> > > > Sent: Tuesday, March 02, 2004 9:23 PM
> > > > To: spr...@li...
> > > > Subject: [Springframework-developer] Lifecycle methods
> > > >
> > > > I think I am missing some basic lifecycle method, but I have
> > > read the docs
> > > > and maybe it does not exist?
> > > >
> > > > I have a cyclic relationship between two beans:
> > > >
> > > > <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>
> > > >
> > > > <bean id=3D"CategoryHierarchy" class=3D"my.CategoryHierarchy">
> > > > <property name=3D"categoryDAO">
> > > > <ref local=3D"CategoryDAO"/>
> > > > </property>
> > > > </bean>
> > > >
> > > > CategoryDAO extends HibernateDaoSupport, so it's
> > > afterPropertiesSet()> method
> > > > uses the session factory to initialize the DAO which creates a
> > > hibernate> template.
> > > >
> > > > The CategoryHierarchy is not a database-aware object and it
> > uses the
> > > > CategoryDAO object for any data-access it may need.
> > > >
> > > > 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.
> > > >
> > > > Here is the order I am seeing:
> > > >
> > > > 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
> > > >
> > > > Is there a lifecycle event that fires *after* the factory has
> > > configured> all
> > > > of the static beans including all aop bindings?
> > > >
> > > > 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?
> > > >
> > > >
> > > >
> > > >
> > > > -------------------------------------------------------
> > > > 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
> > >
> > >
> > > -------------------------------------------------------
> > > 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=1356&alloc_id438&op=3Dclick
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-
> > developer>
> >
> >
> >
> > -------------------------------------------------------
> > 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=1356&alloc_id438&op=3Dclick
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > =
https://lists.sourceforge.net/lists/listinfo/springframework-developer
> >
>=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=1356&alloc_id438&op=3Dick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|