• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring AOP's JDK dynamic proxy

 
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In Spring doc, it says

"Spring recommends that you only annotate concrete classes (and methods of concrete classes) with the @Transactional annotation, as opposed to annotating interfaces. You certainly can place the @Transactional annotation on an interface (or an interface method), but this works only as you would expect it to if you are using interface-based proxies. The fact that Java annotations are not inherited from interfaces means that if you are using class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"), then the transaction settings are not recognized by the proxying and weaving infrastructure, and the object will not be wrapped in a transactional proxy, which would be decidedly bad.



I have a question regarding to the interface-based proxy and how it can see the @Transaction.
Suppose I have :



During runtime, the Spring AOP framework will generate a proxy for the GoodBankService:


According to the Spring doc above, putting @Transactional annoation in the interface works for the interfaced-based proxy (GoodBankServiceProxy). But it also says "Java annotations are not inherited from interfaces..."

My question is if GoodBankServiceProxy class does not inherit the @Transactional annotation from the BankService interface, how can this proxy execute the target object's openAccount method in the transaction ?

 
Himai Minh
Bartender
Posts: 2418
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, as I checked the API in org.springframework.transaction.annotation, @Transactional annotation has a meta-annotation @Inherited. That means this annotation can be inherited from interface. The class that implemented with an interface annotated with @Transactional should be able to create a transaction in AOP framework.
But I don't know why the Spring doc says the class based proxy won't see the @Transactional.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic