Java:带注释的注释(和传递值) [英] Java: Annotated Annotations (and passing values)
问题描述
我有一个注释,其中确实包含其他几个注释,非常类似于此处的注释:
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.
但是,现在,我想添加另一个注释,该注释的参数取决于@OsgiService
的isFactory
参数.
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屋!