Java Reference
In-Depth Information
LISTING 8-8 (continued)
String user = context.getContextData.get("user");
if (user==null){
context.getContextData.put("user", user)'
        return context.proceed();
public void onStart(){
public void onShutdown(){
Because the hooks rely on annotations, method names do not make a difference; you can use any name.
Default‐Level Interceptors
Marking the target advice with Interceptors annotation provides an easy implementation and setup, but
the nature of AOP usually asks for more. Most scenarios require the interceptor to perform its operation
targeting all advices. Imagine adding interceptors for logging or security—targeting only a subset of EJB
wouldn't work. Also, annotating each EJB can become cumbersome and can easily lead to human error.
Java EE offers default‐level interceptors to target all or subsets of EJB matching the naming scheme
provided. Unlike in the previous example, to implement default‐level interceptors, you need XML
coni guration:
Search WWH ::

Custom Search