0

For one of my requirment i have created a inteface with multiple methods and each method annotated with my own java custom annotation. I have a spring aop aspect for my implementation class and i am not able to get my custom annotation in aop aspect. after doing debug i understood my custom annotation is part of the interface and not in implementation class.

How can i get my custom annotation in my implementation methods which declared in interface ?

2
  • Post the relevant code. Commented Jun 18, 2017 at 5:47
  • You can do it by reflection but could you show a source code how you try to get it and your custom annotation Commented Jun 19, 2017 at 8:49

1 Answer 1

1

In Java, annotations are not inhereted from interfaces.With aspects you must annotate the implementation class (and/or methods within that class), not the interface (if any) that the class implements. String aop follows Java’s rule that annotations on interfaces are not inherited. So, if you want to work with your annotation , create an abstract super class to be able to do this.

Inside aspect you work with proxy object and methods are wrapped in proxy calls. But if you know a real class/interface , you can get annotation by reflection api from source class/interface

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the information . For my scenario the interface is implemented by the Spring Integration hence i can't go with the abstract class. I solved this by annotating the interface methods with custom annotation and in my aspect i used reflection to read the annotation values . This solved my problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.