本文介绍了拦截器的排序顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关java ee中有关拦截器的一些教程,但有一些主题未被广泛涵盖。因此,对于回答以下问题的人,我会很高兴:

I am reading some tutorials regarding Interceptors in java ee, but there are some themes which are not covered extensively. Therefore I would be greatful to anyone having answers to the following questions:

1)如果目标类包含,拦截器的执行顺序是什么? @AroundInvoke 方法为:

1) In which order are Interceptors execueted in case the target class contains an @AroundInvoke method as:

@Interceptors({PrimaryInterceptor.class, SecondaryInterceptor.class})
@Stateful
public class OrderBean {
...
    @AroundInvoke
    private void last(InvocationContext ctx) { ... }
...
}

我的印象是,首先它是taget类拦截器,即上一个方法,然后按照注释内指定的顺序使用两个类级别的Interceptor。我对吗?

I have the impression that first it is excecuted the taget class Interceptor, namely the last method in the above case and then the two class-level Interceptors in the order specified inside the annotation. Am I right?

2)什么是超时拦截器(包含带注释的方法 @AroundTimeout )以及什么时候开出?

2) What are Timeout Interceptors (containing methods with the annotation @AroundTimeout) and when are the excecuted?

推荐答案

引用。

默认情况下调用方法时拦截器的排序是

By default the ordering of interceptors when invoking a method are


  • 外部拦截器

  • External interceptors

默认拦截器(如果存在)

Default interceptors, if present

类拦截器(如果存在)

方法拦截器,如果存在

bean类上的拦截器方法(使用 @AroundInvoke

Interceptor method on the bean class (using @AroundInvoke)

在每个组(默认,类,方法)中,拦截器的顺序是从<$ c中定义的从左到右$ c> @Interceptors 注释,然后是 XML 拦截器。

Within each group (default, class, method) the order of the interceptors are from left to right as defined in the @Interceptors annotation, and then the XML interceptors.

对于第二个问题 - @AroundTimeout 与EJB计时器一起使用,每当方法注释时都会触发拦截器 @Schedule 超时 - 请参阅

And for the second question - @AroundTimeout is used together with EJB timers, interceptor is fired whenever method annotated with @Schedule timeouts - see this example.

这篇关于拦截器的排序顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 08:34