How to define order of method interceptors in Guice?

后端 未结 1 842
南方客
南方客 2021-02-04 11:24

Sometimes there\'s a need to know the order of method interceptors that intercept a method call in Guice. A simple example scenario would be to use guice-persist provided @Trans

1条回答
  •  孤独总比滥情好
    2021-02-04 11:40

    Guice invokes the interceptors in the order in which they were registered. So if you define them something like this:

    bindInterceptor(any(), annotatedWith(Retry.class), retryInterceptor);
    bindInterceptor(any(), annotatedWith(Transactional.class), transactionalInterceptor);
    

    or

    bindInterceptor(any(), annotatedWith(Retry.class), retryInterceptor, transactionalInterceptor);
    

    the retryInterceptor will be executed before the transactionalInterceptor.

    Same applies if you have multiple modules - the interceptors from first module are executed before the interceptors of the seconds module and so on.

    0 讨论(0)
提交回复
热议问题