简体   繁体   English

如何使用Spring扫描注释和分配给它们的值

[英]How to scan for Annotations and the values assigned to them Using Spring

I want to scan for @Controller @Path etc other annotations in my application (Controller), since I wanted to document the REST based services. 我想在我的应用程序(控制器)中扫描@Controller @Path等其他注释,因为我想记录基于REST的服务。 I am not able to find an appropriate solution for the same and wanted to device my own solution. 我无法为此找到合适的解决方案,并希望使用自己的解决方案。 I was wondering if there is a component in Spring that would help me to scan through all the controller and help me to fetch out this information. 我想知道Spring中是否有一个组件可以帮助我扫描所有控制器并帮助我获取此信息。 I would like to have a custom build scanner from scratch. 我想从头开始有一个自定义的构建扫描仪。 Please point me to the API in Spring that would help me do so. 请在春季将我指向该API,以帮助我这样做。 I would like to build a customized documentation tool. 我想构建一个自定义的文档工具。

One way to fetch all classes from your package and check through reflection like 一种从包中获取所有类并通过反射进行检查的方法,例如

SomeController.class.isAnnotationPresent(Controller.class)

and the other good way is already specified by @Ralph 另一个好方法已经由@Ralph指定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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