Announcement Announcement Module
Collapse
No announcement yet.
Beans with abstract methods Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Beans with abstract methods

    Hi guys,
    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!

    Juan

  • #2
    "It turns out that sometimes there are methods in the services that have exactly the same signature as in the DAO"

    Well you can extend from a GenericDAOHibernate<T, ID extends Serializable> signature, in that case, UserDAO extends GenericDAO<User,Integer> will call the super signature and will be empty and you only implement it in the service layer(multiple dao injection, transaction demarcation, multitable query, etc)

    "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)"
    I think you can do it with arid framework, but is not easy because its not documented.

    good luck buddy, enjoy the spring

    Comment

    Working...
    X