【问题标题】:Is there Commons AnnotationUtils like library? (Java)是否有类似库的 Commons AnnotationUtils? (爪哇)
【发布时间】:2010-06-08 19:15:46
【问题描述】:

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

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

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

【问题讨论】:

标签: java spring annotations apache-commons-lang


【解决方案1】:

在 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。

【讨论】:

  • 这实际上是我所做的。我遇到的唯一问题是让 Ivy 知道 spring.jar 包含 spring-core.jar 用于包含我已经使用 spring 的注释项目的项目。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多