This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

method lookup

Oct 9th, 2004, 05:00 PM

currently I'm doing some XML bindung stuff with jakarta commons digester. If you haven't heard of it maybe you know XStream. The point is "digesting" my XML bindings consumes a lot of small prototype objects (e.g. author, adress...).

I wanted to get these prototype objects via spring but I couldn't because my digester instance has no relation to the framework after it gets constructed. After a while I found the topic "lookup-method injection" describing exactly my problem.

I inject Author prototype into xml digester. Every time the digester calls aAuthor.newAuthor() it acquires a new fresh prototyped author object. I`m not sure about this approach. Of couse, it doesn`t scale to heavyweight objectgraphs but in such case you shouldn't use prototyping anyway! right?

Is the digester a class you wrote yourself?
In that case: why don't you just configure the "prototype" instances for your digester with spring and use clone() for retrieving new instances from within your digester? (If you do not want to implement Cloneable, you can alternatively use serialization for creating copies)

BTW: I would find it astonishing to have an instance (non-static) method for creating a new instance.