|
From: <jue...@we...> - 2003-11-27 18:06:17
|
I've just added two methods to DefaultListableBeanFactory: - autowireByName(Object existingBean, boolean dependencyCheck) - autowireByType(Object existingBean, boolean dependencyCheck) Both will also invoke lifecycle methods if the corresponding interfaces = are implemented, like = InitializingBean/BeanFactoryAware/ApplicationContextAware. I'll commit = the changes to CVS promptly. For the time being, those autowire methods will just be defined in = DefaultListableBeanFactory and thus its subclass XmlBeanFactory. I guess = we don't want to require this functionality for all bean factories, so = we shouldn't include them in the BeanFactory/ListableBeanFactory = interfaces. The methods aren't concerned with configuration of the bean = factory either, so Configurable(Listable)BeanFactory isn't the right = place for them either. Juergen =20 -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Federico Spinazzi Sent: Thursday, November 27, 2003 5:42 PM To: spr...@li... Subject: Re: [springframework] Re: [Springframework-user] wiring beans created outside a BeanFactory Rod Johnson wrote: >Yes, I realised when I saw my post on the list that I'd missed the = point. >Sorry Frederico for assuming you had a much simpler problem... > And sorry I once thought you have just developed just another framework=20 ... :-) I would like to try to work on this, with maybe some guidance, it's OK? Thanks you all. Federico >----- Original Message -----=20 >From: "j=FCrgen h=F6ller [werk3AT]" <jue...@we...> >To: <spr...@li...> >Sent: Thursday, November 27, 2003 3:21 PM >Subject: RE: [Springframework-user] wiring beans created outside a >BeanFactory > > >I think what Frederico wants to do is pass an *existing instance* = (coming in >from a network) to a bean factory for filling in dependencies. Of = course, >without a bean definition in the factory, just autowiring would be >possible - but that's something we could consider supporting. > >Juergen > > >-----Original Message----- >From: spr...@li... >[mailto:spr...@li...]On Behalf Of >Rod Johnson >Sent: Thursday, November 27, 2003 3:56 PM >To: spr...@li... >Subject: Re: [Springframework-user] wiring beans created outside a >BeanFactory > > >Frederico, > >Dependencies can be resolved by the context using Inversion of Control. >Please look at the example and my article on TSS: > >http://www.theserverside.com/resources/article.jsp?l=3DSpringFramework > >Simply put something like: > ><property name=3D"store"><ref local=3D"myStoreBeanName"/></property> ><-- resolve other properties as well --> > >In the bean definition for your StoreCommand, using the XmlBeanFactory. > >Or just define it with > ><bean id=3D"store" class=3D"StoreCommand" > autwire=3D"byType" > >and Spring will find the collaborators automagically. > >You don't need to subclass Spring classes or work with bean definitions >directly. > >Regards, >Rod > > =20 > >>Hy, >> >>I would like to know if it is possible to ask a context to resolve the >>dipendencies for a given object. >>Assume I get a Command object from the network and I need to resolve >>some dependencies before execution: >> >>public class StoreCommand implements Command, Serializable { >> private Entity entityToBeStored; >> private Store store; >> private Logger logger; >> >> public StoreCommand(Entity entity) { >> this.entityToBeStored =3D entity; >> } >> >> public void execute() { >> try { >> store.store(entityToBeStored); >> } catch (StoreException e) { >> logger.error("exception rised while storing entity " + >>entityToBeStored, e); >> } >> } >> >> public void setStore(Store store) { >> this.store =3D store; >> } >> >> >> public void setLogger(Logger logger) { >> this.logger =3D logger; >> } >>} >> >>It would be fine if the dependencies on store and logger could be >>resolved dinamically by a BeanFactory. >>I think I've to write something like this (in a subclass of >>AbstractBeanfactory): >> >>RootBeanDefinition beanDefinition =3D new >>RootBeanDefinition(StoreCommand.class, null, false); >>beanDefinition.setAutowire(RootBeanDefinition.AUTOWIRE_BY_TYPE); >>autowireByType("to be wired", beanDefinition, ????); >> >>but then I'm stuck as I connot figure how to get an instance back. >>Thanks, >>Federico >> >> >> >> >>------------------------------------------------------- >>This SF.net email is sponsored by: SF.net Giveback Program. >>Does SourceForge.net help you be more productive? Does it >>help you create better code? SHARE THE LOVE, and help us help >>YOU! Click Here: http://sourceforge.net/donate/ >>_______________________________________________ >>Springframework-user mailing list >>Spr...@li... >>https://lists.sourceforge.net/lists/listinfo/springframework-user >> =20 >> > > > > >------------------------------------------------------- >This SF.net email is sponsored by: SF.net Giveback Program. >Does SourceForge.net help you be more productive? Does it >help you create better code? SHARE THE LOVE, and help us help >YOU! Click Here: http://sourceforge.net/donate/ >_______________________________________________ >Springframework-user mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-user > > >------------------------------------------------------- >This SF.net email is sponsored by: SF.net Giveback Program. >Does SourceForge.net help you be more productive? Does it >help you create better code? SHARE THE LOVE, and help us help >YOU! Click Here: http://sourceforge.net/donate/ >_______________________________________________ >Springframework-user mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-user > > > > >------------------------------------------------------- >This SF.net email is sponsored by: SF.net Giveback Program. >Does SourceForge.net help you be more productive? Does it >help you create better code? SHARE THE LOVE, and help us help >YOU! Click Here: http://sourceforge.net/donate/ >_______________________________________________ >Springframework-user mailing list >Spr...@li... >https://lists.sourceforge.net/lists/listinfo/springframework-user > > > > =20 > ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Springframework-user mailing list Spr...@li... https://lists.sourceforge.net/lists/listinfo/springframework-user |