|
From: Steven D. <ste...@gm...> - 2005-01-07 15:23:15
|
Hi, When I load the application context with the example below I get an exception because a bean with id "test3" cannot be found. I understand this bean does not exist in the scope where it's referenced. Is there a way to make beans with an id or name available in the root scope apart from defining them there? <bean id="test2" class="sandbox.TestObject"> <property name="value"> <list> <bean class="sandbox.TestObject"> <property name="value"> <value>a string</value> </property> </bean> <bean class="sandbox.TestObject"> <property name="value"> <list> <bean id="test3" class="sandbox.TestObject"> <property name="value"> <value>another string</value> </property> </bean> </list> </property> </bean> <bean class="sandbox.TestObject"> <property name="value"> <list> <ref bean="test3"/> </list> </property> </bean> </list> </property> </bean> Steven |
|
From: Juergen H. <ju...@in...> - 2005-01-07 15:34:25
|
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). Juergen -----Original Message----- From: spr...@li... [mailto:spr...@li...]On Behalf Of Steven Devijver Sent: Friday, January 07, 2005 4:23 PM To: spr...@li... Subject: [Springframework-developer] bean factory scope question Hi, When I load the application context with the example below I get an exception because a bean with id "test3" cannot be found. I understand this bean does not exist in the scope where it's referenced. Is there a way to make beans with an id or name available in the root scope apart from defining them there? <bean id="test2" class="sandbox.TestObject"> <property name="value"> <list> <bean class="sandbox.TestObject"> <property name="value"> <value>a string</value> </property> </bean> <bean class="sandbox.TestObject"> <property name="value"> <list> <bean id="test3" class="sandbox.TestObject"> <property name="value"> <value>another string</value> </property> </bean> </list> </property> </bean> <bean class="sandbox.TestObject"> <property name="value"> <list> <ref bean="test3"/> </list> </property> </bean> </list> </property> </bean> Steven ------------------------------------------------------- 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 |
|
From: Steven D. <ste...@gm...> - 2005-01-07 15:41:32
|
When building a hiearchical object graph for configuration purposes it would be nice to be able to reference to other beans that are not at the root level. On the other hand it's also nice to have a strict scope :-) Thanks for your feedback. On Fri, 7 Jan 2005 16:34:10 +0100, Juergen Hoeller <ju...@in...> wrote: > 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). > > Juergen > > > -----Original Message----- > From: spr...@li... > [mailto:spr...@li...]On Behalf > Of Steven Devijver > Sent: Friday, January 07, 2005 4:23 PM > To: spr...@li... > Subject: [Springframework-developer] bean factory scope question > > Hi, > > When I load the application context with the example below I get an > exception because a bean with id "test3" cannot be found. I understand > this bean does not exist in the scope where it's referenced. Is there > a way to make beans with an id or name available in the root scope > apart from defining them there? > > <bean id="test2" class="sandbox.TestObject"> > <property name="value"> > <list> > <bean class="sandbox.TestObject"> > <property name="value"> > <value>a string</value> > </property> > </bean> > <bean class="sandbox.TestObject"> > <property name="value"> > <list> > <bean id="test3" class="sandbox.TestObject"> > <property name="value"> > <value>another string</value> > </property> > </bean> > </list> > </property> > </bean> > <bean class="sandbox.TestObject"> > <property name="value"> > <list> > <ref bean="test3"/> > </list> > </property> > </bean> > </list> > </property> > </bean> > > Steven > > > ------------------------------------------------------- > 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 > > ------------------------------------------------------- > 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 > > |
|
From: James C. <jim...@do...> - 2005-01-07 15:55:58
|
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.=20 For example, I may have an email bean wired to a user management bean. <bean id=3D"usermgmt" class=3D"my.UserManagement"> <property name=3D"emailService"> <ref bean=3D"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=3D"emailService" optional=3D"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). |
|
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
>
>
|
|
From: Steven D. <ste...@gm...> - 2005-01-07 17:33:19
|
> I don't want to reply on the mailing list on this subject. And yet I did :-) Thank god it's friday. |