6

除了直接使用注释 api 并编写我自己的或使用 Springs 之外,我找不到用于查询注释的通用实用程序(静态方法)库:

通常我不介意使用 Springs,但它只是用于处理注释的一个相当大的依赖项。也许有一天,Commons Lang 会有 AnnotationUtils。

人们使用什么来查询注释?

4

2 回答 2

3

在 Spring 2.5.6 版本中,可以使用 spring.jar (2.8 MB) 作为依赖项。对于版本 3,这是不可能的。相反,您必须至少添加对核心、bean、上下文、asm 和表达式模块的依赖项才能启动容器。

由于您只有AnnotationUtils课程,因此核心模块就足够了。您可以在此处找到 Ivy 和 Maven 元素以及下载链接:

http://www.springsource.com/repository/app/search?query=AnnotationUtils

它的大小为 350 KB,而 Apache Commons Lang 2.4 为 258 KB。

于 2010-06-08T22:00:22.420 回答
0

我能够使用 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

于 2020-04-30T12:49:30.867 回答