Java:带注释的注释(和传递值) [英] Java: Annotated Annotations (and passing values)

查看:242
本文介绍了Java:带注释的注释(和传递值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注释,其中确实包含其他几个注释,非常类似于此处的注释:

I have a annotation that does include several other annotations, pretty much like this one here:

@Component // Spring Component
@Interface OsgiService { boolean isFactory() }

表示所有用@OsgiService注释的类也将自动注释为@Component.哪个工作正常.

meaning that all classes annotated with @OsgiService shall automatically also be annotated as @Component. Which works fine.

但是,现在,我想添加另一个注释,该注释的参数取决于@OsgiServiceisFactory参数.

Now however, I'd like to add another annotation, that has a parameter which is dependent of the isFactory parameter of @OsgiService.

@Component // Spring Component
@Scope(isFactory() ? "prototype" : "singleton")
@Interface OsgiService { boolean isFactory() }

这不起作用.但是,由于批注的isFactory属性需要为静态值,因此不应该有这样的东西吗?

Which does not work. However, as isFactory property of an annotation requires to be a static value, shouldn't it be possible to have something like this?

推荐答案

我认为这不可能.

您可以创建两个注释:@OsgiService@OsgiServiceFactory

You can create two annotations: @OsgiService and @OsgiServiceFactory

这篇关于Java:带注释的注释(和传递值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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