What are Interceptors in Java EE?

前端 未结 3 920
旧时难觅i
旧时难觅i 2021-01-30 03:55

I\'m trying to clear my concept about Interceptors in Java EE. I have read Java EE specification but I\'m little confused about it. Please provide me some useful link or tutoria

3条回答
  •  旧时难觅i
    2021-01-30 04:47

    Interceptors are used to add AOP capability to managed beans.

    We can attach Interceptor to our class using @Interceptor annotation. Whenever a method in our class is called, the attached Interceptor will intercept that method invocation and execute its interceptor method.

    This can be achieved using @AroundInvoke annotation ( see example below ).

    We can intercept life cycle events of a class ( object creation,destroy etc) using @AroundConstruct annotation.

    Main difference between Interceptor and Servlet Filters is We can use Interceptor outside WebContext, but Filters are specific to Web applications.

    Common uses of interceptors are logging, auditing, and profiling.

    For more detailed introduction, you can read this article. https://abhirockzz.wordpress.com/2015/01/03/java-ee-interceptors/

提交回复
热议问题