| Author |
Call getter method on bean
|
Chris Siciliano
Greenhorn
Joined: Apr 02, 2012
Posts: 9
|
|
Hello everybody..
is-it possible to call getter method on a spring bean ???
I define 2 beans and i would like to set a property value from first bean to second bean.
Thank's.
|
SCJP6
|
 |
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17234
|
posted

1
|
Chris Siciliano wrote:Hello everybody..
is-it possible to call getter method on a spring bean ???
I define 2 beans and i would like to set a property value from first bean to second bean.
Thank's.
In Spring 3.x Spring introduced the Spring Expression Language, and yes you can do that with the Spring Expression Language SPel
<property name="bean2Property" value="#{bean1.propertyName}"/>
Mark
|
Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
|
 |
Chris Siciliano
Greenhorn
Joined: Apr 02, 2012
Posts: 9
|
|
Thank's for answer. But i use spring 2.5. is there a similar solution with this version of Spring ??
Thank's.
|
 |
Mark Spritzler
ranger
Sheriff
Joined: Feb 05, 2001
Posts: 17234
|
posted

0
|
Chris Siciliano wrote:Thank's for answer. But i use spring 2.5. is there a similar solution with this version of Spring ??
Thank's.
I wouldn't exactly call it similar, but if they both have a same value, you can use Bean Definition inheritance.
But the property name has to be the same in both A and B beans.
You could also move the value into a .properties file and use the PropertyPlaceholderConfigurer.
Mark
|
 |
Saifuddin Merchant
Ranch Hand
Joined: Feb 08, 2009
Posts: 576
|
|
Mark Spritzler wrote:
In Spring 3.x Spring introduced the Spring Expression Language, and yes you can do that with the Spring Expression Language SPel
<property name="bean2Property" value="#{bean1.propertyName}"/>
Mark
That's some good info. I always wondered for a way to do something like this!!
Thanks Mark!
|
Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
|
 |
 |
|
|
subject: Call getter method on bean
|
|
|