简体   繁体   中英

How to detect and process Custom annotations by scanning all classes using spring features

I have some class level and method level custom annotations used in various spring based application classes (mostly rest controllers and POJO service beans).

Now I want to extract & process those annotations from all the applied beans to expose a consolidated report via spring boot actuator.

Since I am trying to develop this report actuator as generic component so it could be bundled with any application (as jar dependency ) and should be able to extract the report for that application, so can not go with a particular package/class name scan in annotation processing.

Thus, I am not sure whats the best way to scan all the classes/method and extract these annotations at runtime. I know I have control of spring's application context but will that make any sense to use in this context.. I am not sure. So need some help in annotation processing in this case.

If you cannot go with a hardcoded package/class name scan, you can just scan for the root with "/" to get all the package/class. This can be easily done with Guava library. Also, once you got the class list, you can iterate through them and get their method name. After that, you can use the Java reflection to find the annotation via their method name. I guess this can be done.

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