|
From: Steven D. <ste...@gm...> - 2005-01-07 17:28:01
|
James,
I don't want to reply on the mailing list on this subject. I'm working
on a tool that introduces processing logic to Spring. I'll call this
tool James for now because I don't want to give away the name yet.
Your example would be:
<bean id="usermgmt" class="...">
<property name="emailService">
<bean parent="james.Defined">
<property
name="beanName"><value>usermgmt.emailService</value></property>
<property name="do">
<bean parent="james.Return">
<property name="value">
<ref bean="usermgmt.emailService"/>
</property>
</bean>
</property>
</bean>
</property>
</bean>
The tools is part of a bigger whole but it will be available within a
month I think. It's nice to see other people may have use for it :-)
Actually the Defined and Return beans don't exist yet but your mail
gave me the inspiration :-)
Steven
On Fri, 7 Jan 2005 10:55:48 -0500, James Cook <jim...@do...> wrote:
> Is there a way to define a bean property that is "optional"? If it exists,
> wire it up, otherwise let it remain null? This can be useful when creating
> Spring-enabled components.
>
> For example, I may have an email bean wired to a user management bean.
>
> <bean id="usermgmt" class="my.UserManagement">
> <property name="emailService">
> <ref bean="usermgmt.emailService" />
> </property>
> </bean>
>
> If the user provided a bean with a name of "usermgmt.emailService" my class
> would use this service to send emails. If the bean was not provided, I would
> skip sending emails or maybe use a default implementation.
>
> Perhaps an optional attribute would help?
> <property name="emailService" optional="true">
>
> I think this will become a bigger deal as people start componentizing there
> spring modules.
>
> One way to solve this now is provide the bean name instead of a bean
> reference to the UserManagement bean. Then this bean is responsible for
> looking up the bean reference and handling it accordingly whether it exists
> or not. This is more in the style of JNDI lookups and not very IoC, plus it
> makes my beans more spring aware than I would like.
>
> > -----Original Message-----
> > Beans that are supposed to be available for references by name indeed need
> > to be defined at the root level. Inner beans are always anonymous and
> > usually don't carry a name. Defining a name for them only adds value if
> > they
> > are aware of their own name (BeanNameAware).
>
> -------------------------------------------------------
> The SF.Net email is sponsored by: Beat the post-holiday blues
> Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
|