"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 ?
posted 1 month ago
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.