• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring beans with the same property name but different references

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is the way we have code currently.



I was wondering if I can have something like below. I want to be able to use TesterTwo or TesterThree in certain scenarios without any changes to the java class referencing the bean.


Is this possible? If yes, how?

Thanks.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under what circumstances. Can it be defined in code. You can use Spring 3.0 Expression Language, or the PropertyPlaceholderConfigurer.

SPel would be #{} where inside the curly braces is some method call or other evaluation that determines what you want to set your ref to.

PropertyPlaceholderConfigurer would be ${variable_name} using a .properties file to store the ref value.

There are always the Factory pattern you can use to create the ref that you need also.

There are many solutions, but without knowing how you determine the ref value you want we can't help more.

Thanks

Mark
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic