Java EE:将一些拦截器注释绑定到一个注释
首先:我想使用Java EE而不是Spring! 我有一些自定义的注释,它们充当拦截器绑定。我在我的方法上使用注释,如下所示:
@Logged
@Secured
@RequestParsed
@ResultHandled
public void doSomething() {
// ...
}
对于某些方法,我想使用其中一个注释,但大多数方法我想使用如下:
@FunctionMethod
public void doSomething() {
// ...
}
我可以将这些注释集捆绑到一个注释中吗?我无法在单个拦截器中编写代码,因为对于某些方法我也想单独使用它们。
我知道可以有一个 @Stereotype 定义,但据我所知,它用于定义整个类而不是单个方法。
First of all: I want to use Java EE not Spring!
I have some self defined annotations which are acting as interceptor bindings. I use the annotations on my methods like this:
@Logged
@Secured
@RequestParsed
@ResultHandled
public void doSomething() {
// ...
}
For some methods I want to use a single of these annotations but most methods I want to use like this:
@FunctionMethod
public void doSomething() {
// ...
}
Can I bundle these set of annotations to a single one? I cannot write the code in a single interceptor because for some methods I want to use them seperately too.
I know that there is a @Stereotype definition possible, but as far as I know, this is used to define a whole class not a single method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在一些知名搜索引擎的帮助下,我在 JBoss Weld 的文档(第 9.6 章拦截器绑定与继承)中找到了解决方案,
我可以使用从其他拦截器绑定继承的拦截器绑定接口。它看起来像这样:
现在我可以在 bean 方法上使用新的拦截器绑定,并且所有拦截器都将被调用:
With help of some well-known search engine I found the solution in the documentation of JBoss Weld (Chapter 9.6 Interceptor binding with inheritance)
I can use an interceptor binding interface which is inherited from other interceptor bindings. It will look like this:
Now I can use the new interceptor binding on the bean method and all of the interceptors will be called:
我想说,你的刻板印象是正确的。
没错,我们找到的示例以及官方 Java EE 6 教程仅在类上使用它作为示例(例如 @Model),但您也可以在自定义注释中声明 @TYPE(MEHOD),然后我假设它有效。
I would say, that you are on the right pass with a stereotype.
It's right, that the examples one finds and also the official Java EE 6 Tutorial only uses it on a class as an example (e.g. @Model), but you may as well declare @TYPE(MEHOD) in your custom annotation and then I assume that it works.