aspose file tools*
The moose likes Struts and the fly likes Spring BeanFactory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Spring BeanFactory" Watch "Spring BeanFactory" New topic
Author

Spring BeanFactory

Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
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


    blog - InfoQ.com
    Matt Raible
    author
    Ranch Hand

    Joined: Jan 11, 2001
    Posts: 114
    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.


    Matt<br /> <br />Author: <a href="http://springlive.com" target="_blank" rel="nofollow">Spring Live</a> and <a href="http://www.apress.com/book/bookDisplay.html?bID=256" target="_blank" rel="nofollow">Pro JSP</a><br />Weblogs: <a href="http://raibledesigns.com" target="_blank" rel="nofollow">Raible Designs</a> <a href="http://jroller.com/page/raible" target="_blank" rel="nofollow">Spring Live Blog</a>
    Alexandru Popescu
    Ranch Hand

    Joined: Jul 12, 2004
    Posts: 995
    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

    Joined: Jul 12, 2004
    Posts: 995
    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

    Joined: Jul 12, 2004
    Posts: 995
    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Spring BeanFactory