Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

using spring expressions

 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
srini carry
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic