1

I have this technical doubt...

If I have an interface

public interface test{
    @Transactional
    public void mymethod();
    }

and then I have my implementation

public class testImpl implements test{
@Override
    public void mymethod(){
        //..do something
    }
}

Since I am using @Override, will my annotation @Transactional, @Lock or any other persist on my implementation? or will overriden by the interface method without adding any special behaviour from the annotation?

jpganz18
  • 5,508
  • 17
  • 66
  • 115
  • 1
    Note that the answer *in general* is not necessarily the answer *for Spring*, which has some extraordinarily detailed handling for this type of situation, manually inspecting supertypes and composing the appropriate behavior. – chrylis -cautiouslyoptimistic- Jan 26 '17 at 21:31

1 Answers1

0

Best answer I have read on this matter:

See this link https://stackoverflow.com/a/5551597/3447634

COPY OF THAT ANSWER: "It really all depends on your application architecture, in my opinion. It depends on how you are proxying your classes. If you have your app set to "proxy-target-class='true'" (in your application context, then your @Transactional information wont be picked up if you annotate the Interface.

Check out The Spring Docs -- "Tips" for more information.

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."

Community
  • 1
  • 1
GavinF
  • 387
  • 2
  • 15