Ana*_*oly 4 jsf interceptor cdi
我有一个带有私有方法的CDI bean.我写了一个拦截器如下:
拦截器的代码:
@Interceptor
@TimeMeasure
public class TimeWatcher implements Serializable {
@AroundInvoke
public Object logMethodEntry(InvocationContext ctx) throws Exception {
long t0 = System.nanoTime();
try {
return ctx.proceed();
} finally {
long dt = System.nanoTime() - t0;
System.out.println("Method execution time: " + ctx.getMethod().getName() + " - " + dt);
}
}
}
Run Code Online (Sandbox Code Playgroud)
注释的代码:
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@InterceptorBinding
@Target({TYPE, METHOD})
@Retention(RUNTIME)
public @interface TimeMeasure {
}
Run Code Online (Sandbox Code Playgroud)
一切只适用于外部调用的公共方法,如果我从CDI bean中调用方法它不起作用.我使用JSF 2.0 MyFaces和Omnifaces来完成@ViewScoped
先感谢您.
归档时间: |
|
查看次数: |
1971 次 |
最近记录: |