How do Java method annotations work in conjunction with method overriding?
Copied verbatim from http://www.eclipse.org/aspectj/doc/released/adk15notebook/annotations.html#annotation-inheritance:
Annotation Inheritance
It is important to understand the rules relating to inheritance of annotations, as these have a bearing on join point matching based on the presence or absence of annotations.
By default annotations are not inherited. Given the following program
@MyAnnotation
class Super {
@Oneway public void foo() {}
}
class Sub extends Super {
public void foo() {}
}
Then
Sub
does not have theMyAnnotation
annotation, andSub.foo()
is not an@Oneway
method, despite the fact that it overridesSuper.foo()
which is.If an annotation type has the meta-annotation
@Inherited
then an annotation of that type on a class will cause the annotation to be inherited by sub-classes. So, in the example above, if theMyAnnotation
type had the@Inherited
attribute, thenSub
would have theMyAnnotation
annotation.
@Inherited
annotations are not inherited when used to annotate anything other than a type. A type that implements one or more interfaces never inherits any annotations from the interfaces it implements.
Annotation Reflection for Method overrided
Try using AnnotationUtils
class from Spring's core.
I think you'll get the annotation from parent's class as you need.
default annotation for method of an interface
Annotation on methods aren't inherited as properly explained in this
answer though if you want to check if the method have the annotation you can explicity write a custom function that will do it for you, also well explained here
Override transactional method
What you are actually asking : is the @Transactional annotation on the method inherited.
Short answer : no. Annotations on methods are never inherited.
Long answer : see this post.
Related Topics
Java Generic Class - Determine Type
How to Get Annotations of a Member Variable
How to Turn Off the Httpsession in Web.Xml
Accurate Sleep for Java on Windows
Access Maven Properties Defined in the Pom
How to Send Data to Com Port Using Java
Is 1/0 a Legal Java Expression
What Is Java_Home? How Does the Jvm Find the Javac Path Stored in Java_Home
Jpa, How to Use the Same Class (Entity) to Map Different Tables
How to Declare a 2D String Arraylist
Maximum Amount of Memory Per Java Process on Windows
Javamail Could Not Convert Socket to Tls Gmail
How to Call Super Constructor in Lombok
Java: What's the Difference Between Autoboxing and Casting
Java Error: Cannot Make a Static Reference to the Non-Static Method