|
From: Christophe V. <c.v...@pa...> - 2004-01-20 23:56:10
|
On Tuesday 20 January 2004 23:11, Colin Sampaleanu wrote: > These are lifecycle methods which apply to beans created by the > container (spring) itself. If the container is not actually creating an > object, then it can't and shouldn't call lifecycle methods on it. > > All that MethodInvokingFactoryBean is doing is calling a method on > another bean, but in this case it has nothing to do with the fact that > that method is then creating a new object. So with w/regards to the > test.Thingy class, it is only created via a 'new Thingy'()' call in > ThingyCreater, and you can not expect that any lifecycle methods will be > called on it by Spring. > Thanks, that makes lots of sense. The reason I wanted to be able to do this is the following: I have an object, that is actually a loaded hibernate instance (and the only instance of its class). It is needed in many places in my application (actions, tablemodels, ... ; this is a standalone swing app), as it is the central object that holds all the data that will be manipulated and is in memory all the time. I now load this instance via a call on a Hibernate DAO class using the MethodFactoryBean, and give references to it for anything that needs it (practically every panel, action, ...). So far so good. It would have been handy to let this object handle certain ApplicationEvents, which is why I implemented this interface, but I now know that this won't work. (As a sidenote, ApplicationListener is very handy in swing apps, you can create very loose coupled components, without the need to create and register all sorts of custom Listeners, and it doesn't give any significant performance drawbacks because there are so few ApplicationListeners.) I suppose I could register an instance of another class, also let it implement ApplicationListener, and then let it the delegate the events to the hibernate instance, but now I'm wondering if there is a more direct way to do this (maybe by somehow making the hibernated object a "real" spring object). -- Kind regards, Christophe Vanfleteren |