Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call getter method on bean

 
Chris Siciliano
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Chris Siciliano
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic