wood burning stoves 2.0*
The moose likes Spring and the fly likes using spring expressions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "using spring expressions" Watch "using spring expressions" New topic
Author

using spring expressions

srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
I need help in using the below configration using spring expressions


I have a properties object which has system properties

here is the spring configration



to inject a property from this bean into other bean I do this




and I inject the bean serviceUrl into other beans.

<bean id="somebean" class="blah.....blah.SomeClass">
<property name="someproperty" ref="serviceUrl " />
</bean>

is there anyway I can avoid creating aserviceUrl bean and directly inject the propery into other beans using spring expressions?

Please advice
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Yes.

#{systemProperties['ssi_launch_url']}

so if I have a bean class that I want to assign a property of that value I can do it.



Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
Mark Spritzler wrote:Yes.

#{systemProperties['ssi_launch_url']}

so if I have a bean class that I want to assign a property of that value I can do it.



Mark


my object is this




and I tried this




this did not work cant I do this ?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well because it is a getter, you can do, and one other thing, I think systemProperties is a predefined implicit reference in Spring Expression Language.

so maybe the AuditProperties bean should be called auditProperties instead

so change the bean name to auditProperties and try

Wait a second. Why aren't those values just in a .properties file that you load in.

so in a file called auditProperties.properties put



Then you can load the file via

<util:properties id="auditProperties" location="locationOf/auditProperties.properties/>

Then you can use


#{auditProperties['ORG_ID']}

What you are currently doing is reinventing the wheel. Even if you didn't want it in a .properties file but still in code, you are reinventing the wheel because Java SDK comes with a class called Properties.


Mark">
srini carry
Ranch Hand

Joined: Nov 30, 2007
Posts: 83
This is some example I can ofcourse put this in a property file , but this is a groovy file which I can change at runtime and app gets updated automatically , Please advice if I have this spring bean and I want to call getPropertyValue using spring expressions how to ?

Mark Spritzler wrote:Well because it is a getter, you can do, and one other thing, I think systemProperties is a predefined implicit reference in Spring Expression Language.

so maybe the AuditProperties bean should be called auditProperties instead

so change the bean name to auditProperties and try

Wait a second. Why aren't those values just in a .properties file that you load in.

so in a file called auditProperties.properties put



Then you can load the file via

<util:properties id="auditProperties" location="locationOf/auditProperties.properties/>

Then you can use


#{auditProperties['ORG_ID']}

What you are currently doing is reinventing the wheel. Even if you didn't want it in a .properties file but still in code, you are reinventing the wheel because Java SDK comes with a class called Properties.


Mark">
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

srini carry wrote:This is some example I can ofcourse put this in a property file , but this is a groovy file which I can change at runtime and app gets updated automatically , Please advice if I have this spring bean and I want to call getPropertyValue using spring expressions how to ?


I don't understand the question. If I have an object that is a bean, has an id, and has a property. I get it via bean name dot property name. or if the property requires a dot in the name, then use brackets. Check out the Core Spring documentation.

#{beanName.propertyName} or

#{beanName['propertyName]

Both work.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using spring expressions
 
Similar Threads
Spring transaction
Error while Proxying DAO Classes
using spring expressions
spring transaction management only
Setting property value of Bean dynamically through code.