-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Affects: Spring framework version 5
The Spring Reference Manual states the following.
The Spring team recommends that you annotate only 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 use interface-based proxies. The fact that Java annotations are not inherited from interfaces means that, if you use class-based proxies (proxy-target-class="true") or the weaving-based aspect (mode="aspectj"), the transaction settings are not recognized by the proxying and weaving infrastructure, and the object is not wrapped in a transactional proxy, which would be decidedly bad.
But I tried an example using CGLIB proxy, and annotate @Transactional
on an interface. I expect an error. But it does not throw any error, to my surprise. I guess Spring documentation needs to be updated, maybe?
We posted our code example here in coderanch.com/forum and one staff recommends me to ask Spring community. The detail code example and discussion is here. Please take a look: https://coderanch.com/t/714204/frameworks/Spring-Transactional-inheritance
Thanks.