简体   繁体   中英

How to get Java custom annotations from Implementation class methods

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 ?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM