Jan 23rd, 2008, 07:21 AM
Beans with abstract methods
I'm working on a project that's based on a typical spring architecture: there are some service objects used primarily for transactional demarcation, and DAOs that conceal the persistence details to the upper layers.
It turns out that sometimes there are methods in the services that have exactly the same signature as in the DAOs. (we don't access the DAO directly because we need a current transaction to be open)
I bet that by now you can guess what I want to do
I'd like to declare abstract methods in the services so that I can forward the message to the DAO (in a method injection fashion - I think that method injection, however, wouldn't work because isn't too generic, since I need to apply such 'injection' to beans of many classes, and I wouldn't like this behavior to be configured)
I think that (despite I've been unable to do it so far) it's 100% viable because spring may instantiate a subclass-based proxy (so it implements the abstract methods).
I tried to implement the additional behavior (of forwarding the message) with an @AspectJ aspect, but unfortunately Spring throws an exception - cannot instantiate a bean of an abstract class (the service object)
Isn't any way to achieve this? I hope that I expressed myself okay.
I'll appreciate your thoughts!
Thanks in advance!