Should make the Spring wiring easier! Ross, didn't you put a comment in the code saying that you were looking for methods such as these?


Cheers,
matthew

Begin forwarded message:

From: jürgen höller [werk3AT] <[EMAIL PROTECTED]>
Date: November 27, 2003 12:04:14 PM CST
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Subject: Re: [Springframework-user] wiring beans created outside a BeanFactory
Reply-To:
[EMAIL PROTECTED]

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


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Federico Spinazzi
Sent: Thursday, November 27, 2003 5:42 PM
To: [EMAIL PROTECTED]
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
... :-)
I would like to try to work on this, with maybe some guidance, it's OK?
Thanks you all.
Federico


----- Original Message -----
From: "jürgen höller [werk3AT]" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
Rod Johnson
Sent: Thursday, November 27, 2003 3:56 PM
To: [EMAIL PROTECTED]
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=SpringFramework

Simply put something like:

<property name="store"><ref local="myStoreBeanName"/></property>
<-- resolve other properties as well -->

In the bean definition for your StoreCommand, using the XmlBeanFactory.

Or just define it with

<bean id="store" class="StoreCommand"
autwire="byType"

and Spring will find the collaborators automagically.

You don't need to subclass Spring classes or work with bean definitions
directly.

Regards,
Rod



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 = 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 = store;
}


public void setLogger(Logger logger) {
this.logger = 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 = 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
[EMAIL PROTECTED]
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
[EMAIL PROTECTED]
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
[EMAIL PROTECTED]
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
[EMAIL PROTECTED]
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
[EMAIL PROTECTED]
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
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/springframework-user

Reply via email to