Vi em alguns lugares a seguinte implementação:
@Interceptors(TesteInterceptor.class)
public @interface Custom{}
public class TesteInterceptor {
@PostConstruct
public void myPostConstruct(InvocationContext ctx) {
System.out.println("Interceptor @PostConstruct: " + ctx.getTarget().getClass().getName());
}
@PreDestroy
public void myPreDestroy(InvocationContext ctx) {
System.out.println("Interceptor @PreDestroy: " + ctx.getTarget().getClass().getName());
}
@PostActivate
public void postActivate(InvocationContext ctx) {
System.out.println("Interceptor @PostActivate: " + ctx.getTarget().getClass().getName());
}
@PrePassivate
public void prePassivate(InvocationContext ctx) {
System.out.println("Interceptor @PrePassivate: " + ctx.getTarget().getClass().getName());
}
@AroundInvoke
public Object businessIntercept(InvocationContext ctx) throws Exception {
System.out.println("Interceptor @AroundInvoke: " + ctx.getTarget().getClass().getName());
Object result = null;
try {
// PreInvoke: do something before handing control to the next in
// chain
result = ctx.proceed();
return result;
} finally {
// PostInvoke: do something (cleanup, etc) after the main processing
// is done
}
}
@Custom public class Teste {}
Isto realmente é possível? Não está funcionado para mim.