Java Reference
In-Depth Information
stripesbook.nonext.Interceptor1,
stripesbook.nonext.Interceptor2,
stripesbook.nonext.Interceptor3
</param-value>
</init-param>
</filter>
Let's say that those three interceptors all run both before and after the
same life-cycle stage. Suppose further we also have a
@Before
and an
@After
method in the action bean for the same life-cycle stage. If there
are no interruptions, things happen in the following order:
1. @Before
2. Interceptor1, before
3. Interceptor2, before
4. Interceptor3, before
5. Interceptor3, after
6. Interceptor2, after
7. Interceptor1, after
8. @After
13.4
Interceptor Example: Adding Support for Guice
looked at using Spring for dependency injection. Guice (
http://code.
google.com/p/google-guice
)
is another DI container, for which Stripes
does not have built-in support (at least not in the latest version of
Stripes as of this writing). We'll add support for Guice DI using an
interceptor. Tapping into Stripes and “guicing” up action beans is sur-
prisingly easy!
The life-cycle stage that interests us is the
ActionBeanResolution
stage.
Stripes creates an instance of the action bean during this stage, and the
action bean context has already been manufactured. We can intercept
both objects and inject Guice-annotated dependencies into them before
they are returned:
package
stripesbook.ext.guice.interceptor;
@Intercepts(LifecycleStage.ActionBeanResolution)
public class
GuiceInterceptor
implements
Interceptor, ConfigurableComponent
{
/
*
...
*
/
Search WWH ::
Custom Search