• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Spring BeanFactory

 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
     
    author
    Posts: 114
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    Whatever you say buddy! And I believe this tiny ad too:
    Thread Boost feature
    https://coderanch.com/t/674455/Thread-Boost-feature
    reply
      Bookmark Topic Watch Topic
    • New Topic