Question

What is the difference between Interceptors and Callbacks? Can I use @AroundConstruct and @PostConstruct interchangeably, will they always be involve (more or less) the same time?

Était-ce utile?

La solution

As pointed out in the comments, the overhead of either is probably negligible, and not worth worrying about until you actually have a real problem to talk about.

As for the sequence of events (and other differences), the javadocs for AroundConstruct and PostConstruct answer that.

AroundConstruct must be defined on an interceptor, and the real constructor is invoked after the last such interceptor calls the proceed method on the InvocationContext. So these will technically run before the constructor, but you get control back after it runs (thus the name "Around"), so you can do post-processing as well.

PostConstruct can be use defined on an interceptor or on any void method with no parameters on the object itself. It is invoked after the container has finished with dependency injection (thus the name "Post").

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top