我找不到一个通用的实用程序(静态方法)库来查询注释,除了直接使用注释API并编写自己的代码或使用Spring的以下内容:
通常情况下,使用Spring没有问题,但仅为处理注释而添加如此大的依赖可能有些过分。也许Commons Lang将来会有AnnotationUtils。
人们正在使用什么来查询注释?
人们正在使用什么来查询注释?
在Spring 2.5.6版本中,可以使用spring.jar(2.8 MB)作为依赖项。但在3版本中,这是不可能的。相反,您必须至少添加核心、bean、上下文、asm和expression模块作为启动容器的最小依赖项。
由于您只需要AnnotationUtils
类,因此仅使用核心模块即可。
您可以在此处找到Ivy和Maven元素以及下载链接:
http://www.springsource.com/repository/app/search?query=AnnotationUtils
它的大小为350 KB,而Apache Commons Lang 2.4的大小为258 KB。
我使用Apache lang3的MethodUtils#getAnnotation解决了我的用例。 https://commons.apache.org/proper/commons-lang/javadocs/api-3.6/org/apache/commons/lang3/reflect/MethodUtils.html#getAnnotation-java.lang.reflect.Method-java.lang.Class-boolean-boolean-
此外,如果你正在寻找上面提到的Spring AnnotationUtils,我相信它最终会出现在'spring-context-support'中。 https://mvnrepository.com/artifact/org.springframework/spring-context-support