类AnnotationLiteral的独立版本? [英] Standalone version of class AnnotationLiteral?

查看:282
本文介绍了类AnnotationLiteral的独立版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该CDI(上下文依赖注入)框架包含真棒类的 javax.enterprise.util.AnnotationLiteral ,使得它很容易创建注释(用于测试especaly有用)的一个实例。

The CDI (Context Dependency Injection) Framework contains the awesome class javax.enterprise.util.AnnotationLiteral that makes it very easy to create an instance of an Annotation (especaly useful for tests).

我想使用的Util类在自己的图书馆。但是因为我的图书馆提与CDI做的,我不希望有其他所有的东西CDI。
幸运的是AnnotationLiteral不使用任何其他类比标准的Java类,所以这应该一般是可能的。

I want to use that util class in my own library. But because my library has noting to do with CDI, I do not want to have all the other CDI stuff. Fortunately AnnotationLiteral does not use any other classes than standard java classes, so this should be possible in general.

截至目前包含AnnotationLiteral最小的图书馆是官方 CDI-API

Up to now the smallest Library that contains AnnotationLiteral is the official CDI-API

<dependency>
   <groupId>javax.enterprise</groupId>
   <artifactId>cdi-api</artifactId>
   <version>1.0</version>
</dependency>

但即使我切断了所有的依赖关系(由行家排除),罐子将包含很多其他的CDI-API和-SPI的东西。

But even if I cut off all the dependencies (by maven exclude), the jar will contain a lot of other CDI-API and -SPI stuff.

所以我的问题是:有没有已经只包含 util.AnnotationLiteral 类的一些(或多或少官员)(Maven的)库,或至少没有那么多其他的东西?

So my question is: Is there already some (more or less official) (maven) library that contains only the util.AnnotationLiteral Class, or at least not so much other stuff?

推荐答案

AnnotationLiteral 可以在<一个可以找到一个Apache授权版本href=\"http://svn.apache.org/repos/asf/geronimo/specs/trunk/geronimo-jcdi_1.0_spec/src/main/java/javax/enterprise/util/AnnotationLiteral.java\"相对=nofollow> Geronimo的API 。它看起来并不像它有任何依赖于CDI的其他部分。如果你不需要的平等和散列code实现它在测试中提供你甚至可以直接实现一个注释界面。这不是真正的好作风,但绝对有可能的。 CDI需要为它的逻辑预选赛附加平等和散列code实现。下面是使用JSF的一个例子 ManagedBean 注释:

An Apache licensed version of AnnotationLiteral can be found in the geronimo api. It does not look like it has any dependencies to other parts of CDI. If you don't need the equals and hashCode implementation it provides in your tests you could even directly implement an annotation interface. This is not really good style but definitely possible. CDI needs the additional equals and hashCode implementation for its Qualifier logic. Here is an example using the jsf ManagedBean annotation:

public static ManagedBean test = new ManagedBean() {
    @Override
    public String name() {
        return "test";
    }

    @Override
    public boolean eager() {
        return false;
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        return ManagedBean.class;
    }  
};

这篇关于类AnnotationLiteral的独立版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆