开发者

Java: Annotated Annotations (and passing values)

开发者 https://www.devze.com 2023-01-20 17:55 出处:网络
I have a annotation that does include several other annotations, pretty much like this one here: @Component // Spring Component

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

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

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

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() }

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 th开发者_如何学编程is?


I don't think this is possible.

You can create two annotations: @OsgiService and @OsgiServiceFactory

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号