java - Differences between @Interceptors and @InterceptorBinding + @Logged? -


seems there 2 ways binding interceptor target class/method:

  1. @interceptors on target class/method
  2. declare interceptor binding type(aka, custom annotation annotated @interceptorbinding itself, example @logged), , using on target class/method

i using interceptor in cdi environment. question is, unnecessary declare interceptor binding type if using @interceptors binding interceptor target methods?

if answer yes, why intellij idea complaint me error

@interceptor must specify @ least 1 interceptor binding

when not annotating interceptor binding type on interceptor?

if answer no, binding interceptor target class/method @interceptors(arrayofmyinceptor) directly, why declare interceptor binding type , using on interceptor?


search web cannt found difference of 2 approaches, hope can solve problem.

thank patience.

the annotations @interceptor , other costum annotations @logged supposed invoked on interceptor class, e.g.

@logged @interceptor @priority(interceptor.priority.application) public class loggedinterceptor implements serializable { ... } 

the annotation @interceptorbinding has invoked on annotation want create make clear it's of "interceptor qualifier".

@inherited @interceptorbinding @retention(runtime) @target({method, type}) public @interface logged { } 

then can invoke interceptor-binding annotation on (managed) bean or methods.

@logged public string pay() {...}  @logged public void reset() {...} 

see java tutorial more https://docs.oracle.com/javaee/7/tutorial/cdi-adv006.htm

edit

because misread question, here's edit: annotation @interceptors collection of interceptors. passing several interceptor classes (e.g. loggedinterceptor @logged) value variable of applied @interceptors annotation inteceptor bindings invoked:

@interceptors({loggedinterceptor.class, otherinterceptor.class,.....}) 

thus need @ least 1 interceptor binding @interceptors

so need interceptor binding interceptor class but not target class since it's mentioned in @interceptors annotation.

see api documentation https://docs.oracle.com/javaee/7/api/javax/interceptor/interceptors.html


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -