Announcement Announcement Module
Collapse
No announcement yet.
Configure a bean after creation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configure a bean after creation

    Hello Springers,

    I'm investigating whether I can use Spring to configure a bean after its creation. I'm using Tapestry, and the creation of my Page object is controlled by the framework. I'd like to be able to add a call to something like:

    beanFactory.populate(thisPage, idOfPageInFactory);

    during the pageBeginRender callback method. Then I'd like to "deconfigure" it during the pageEndRender method.

    I found something similar,
    AutowireCapableBeanFactory.autowireBeanProperties( )

    which is exactly what I want (I think). However, it only allows autowiring, not explicit wiring.

    Is this possible? If it isn't, is that because it's a bad idea? Would this be a good feature request?

    Cheers,
    Nick

  • #2
    Nick,

    There's nothing that will work to populate an existing instance, but not use autowiring.

    The existing autowire method (of an existing bean) is easy to handle since by definition there is no bean definition required.

    Your use case, which I can't really recall having been requested by anybody, sounds fairly useful, and is not incredibly hard to do either, but the call would obviously have to provide some indication to the container as to which bean definition to use (which could be implicit if there is only one def for a class of that type). It's really just a version of the existing getBean() method, with the bean construction pre-handled. Implicit in this is I think the assumption that the bean is a prototype as far as the Spring container is concerned, i.e. it does not try to manage its lifecylce as it would for non-prototoype beans.

    The best thing to do is probably to file a feature request in JIRA. I don't think that Juergen, Rod or I would have a problem adding this for the 1.2 timeframe.

    Regards,

    Comment


    • #3
      Thanks Colin for the prompt reply:

      http://opensource.atlassian.com/proj...browse/SPR-266

      Cheers,
      Nick

      Comment

      Working...
      X