Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Spring AOP's JDK dynamic proxy

 
Ranch Foreman
Posts: 1906
13
  • Mark post as helpful
  • send pies
  • 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
Ranch Foreman
Posts: 1906
13
  • Mark post as helpful
  • send pies
  • 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.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic