Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring BeanFactory

 
Alexandru Popescu
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I would like to have a BeanFactory that behaves in the following way:
  • I can use properties inside the definitions ( i meen ${prop.value})
  • apply a PropertyPlaceholderConfigurer to obtain the real values and retrieve the beans (this is done programmatically)
  • apply another PropertyPlaceholderConfigurer and obtain another set of beans (same as above)


  • Actually this behavior is not available. After applying the 1st PropertyPlaceholderConfigurer the values ${prop.value} are lost foreever, so applying another PropertyPlaceholderConfigurer will do in fact nothing.

    The solution I see for this are:
  • either clone in a way the BeanFactory and apply PropertyPlaceholderConfigurer on clones (till this moment I couldn't figure out a way to implement this)
  • or create a custom BeanFactory (probably extending DefaultListableBeanFactory) that will be able to keep the original values after applying a property placeholder


  • Does anybody see any other solution for this?

    ./pope
     
    Matt Raible
    author
    Ranch Hand
    Posts: 114
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The http://www.springframework.org/docs/api/org/springframework/beans/factory/config/PropertyOverrideConfigurer.html might help. It allows you to override properties in your XML files with a properties file.
     
    Alexandru Popescu
    Ranch Hand
    Posts: 995
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Matt. Just now I was reading the code in order to figure out if PropertyOverrideConfigurer is doing what I want or not :-).

    I'll be back to confirm (hopefully).

    ./pope
     
    Alexandru Popescu
    Ranch Hand
    Posts: 995
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have 2 news: as always 1 is good and 1 is bad :-).
    Good one: in one case this helps me.
    Bad one: in the other one this doesn't help me.

    I will present hereunder what I am trying:


    The scenario is quite simple: I want to obtain context bean in a runtime configured way. So I try to set the ref bean at runtime to one of the possible values projectContext1/projectContext2.

    ./pope
     
    Alexandru Popescu
    Ranch Hand
    Posts: 995
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I have published also my question here. And till now nobody had a comment on it, so I guess either I am completely insane , or the solution I see is correct.

    ./pope
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic