|
From: Colin S. <col...@ex...> - 2003-11-21 16:09:06
|
(diverting to dev list, as this is more appropriate there)
This would be of some use.
Of course, the variant to adding more and more mechanisms to access
other objects is to put in some (optional) support for an expresion
language inside the bean factory. I've been thinking about this for a
while now.
So assuming that there is a generic expression language plugin facility,
and which expression language to use is denoted by a prefix, a
hypothetical OGNL example for your case would be:
<bean id="myBean" class="org.me.myClass">
<property
name="myProp"><expr>ognl:@System@getProperties()['my.property.name']</expr></property>
</bean>
And if you expose the current factory into the OGNL context, then you
could have expressions such as:
<bean id="myBean" class="org.me.myClass">
<property
name="myProp"><expr>ognl:factory.getBean('another-bean-id').someProperty</expr></property>
</bean>
and so on...
Eric Pederson wrote:
> It would be very handy to be able to set bean properties based on the
> value of system properties. That would allow system
> administrators to set application properties without touching a .war
> or .jar that has an applicationContext.xml or
> PropertyResourceConfigurer property file inside of it.
>
> For example, I would start up my JVM with a flag -Dmy.property.name=foo
>
> The applicationContent.xml in the .war or .jar would have
>
> <bean id="myBean" class="org.me.myClass">
> <property
> name="myProp"><sysproperty>my.property.name</sysproperty></property>
> </bean>
>
> This would set myBean.myProp to "foo".
>
> Thoughts?
>
>
>
> Eric Pederson
> eri...@ac...
|
|
From: Rod J. <rod...@in...> - 2003-11-21 16:24:21
|
> Of course, the variant to adding more and more mechanisms to access
> other objects is to put in some (optional) support for an expresion
> language inside the bean factory. I've been thinking about this for a
> while now.
+1
>
> So assuming that there is a generic expression language plugin facility,
> and which expression language to use is denoted by a prefix, a
> hypothetical OGNL example for your case would be:
>
> <bean id="myBean" class="org.me.myClass">
> <property
>
name="myProp"><expr>ognl:@System@getProperties()['my.property.name']</expr><
/property>
> </bean>
>
> And if you expose the current factory into the OGNL context, then you
> could have expressions such as:
>
> <bean id="myBean" class="org.me.myClass">
> <property
>
name="myProp"><expr>ognl:factory.getBean('another-bean-id').someProperty</ex
pr></property>
> </bean>
I think it's important that we don't sink under steady feature creep of
supporting more and more single-scenario solutions. So a more general
solution would be better.
Another 1.1 feature, perhaps.
Regards,
Rod
|
|
From: Colin S. <col...@ex...> - 2003-11-21 17:05:32
|
Rod Johnson wrote:
>>Of course, the variant to adding more and more mechanisms to access
>>other objects is to put in some (optional) support for an expresion
>>language inside the bean factory. I've been thinking about this for a
>>while now.
>>
>>
>+1
>
>
>
>>So assuming that there is a generic expression language plugin facility,
>>and which expression language to use is denoted by a prefix, a
>>hypothetical OGNL example for your case would be:
>>
>><bean id="myBean" class="org.me.myClass">
>> <property
>>
>>
>>
>name="myProp"><expr>ognl:@System@getProperties()['my.property.name']</expr><
>/property>
>
>
>></bean>
>>
>>And if you expose the current factory into the OGNL context, then you
>>could have expressions such as:
>>
>><bean id="myBean" class="org.me.myClass">
>> <property
>>
>>
>>
>name="myProp"><expr>ognl:factory.getBean('another-bean-id').someProperty</ex
>pr></property>
>
>
>></bean>
>>
>>
>
>I think it's important that we don't sink under steady feature creep of
>supporting more and more single-scenario solutions. So a more general
>solution would be better.
>
>Another 1.1 feature, perhaps.
>
>
>
There is of course a tradeoff here, where you want to cover the guy
using a basic BeanFactory in an Applet or somewhere like that where
every last byte counts, and get him a minimal set of functionality, but
for the cases where size is not as much of an issue, there are more
powerful/general solutions.
In this particular case (getting a system property), I think this will
be able to be handled by the MethodCallFactoryBean I am writing right
now, in a slightly more verbose fashion...
<bean id="sysProps"
class="org.springframework.beans.factory.config.MethodCallFactoryBean">
<property
name="staticMethod"><value>java.lang.System.getProperties</value></property>
</bean>
<bean id="mySystemProp"
class="org.springframework.beans.factory.config.MethodCallFactoryBean">
<property name="target"><ref local='sysProps'/></property>
<property name="targetMethod"><value>getProperty</value></property>
<property name="args">
<list>
<value>my.property.name</value>
</list>
</bean>
So this would cover people using a base beanfactory, while people
willing to bring in a real expression processor, would have more concise
mechanisms...
|