是否可以在没有应用程序服务器的情况下使用拦截器,例如仅在命令行工具中使用?
我尝试了以下内容,但我没有看到任何输出:
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
public class PerformanceInterceptor {
@AroundInvoke
Object measureTime(InvocationContext ctx) throws Exception {
System.out.println("STARTING"); //I don't see this
}
}
class MyTest() {
@Interceptors(PerformanceInterceptor.class)
void execute() {
System.out.println("RUNNING"); //I see this
}
}
可能是什么问题?
答案 0 :(得分:0)
请查看此示例:http://www.byteslounge.com/tutorials/java-ee-ejb-interceptors-tutorial-and-example。 BTW,很棒的Java EE 6功能。
没有EJB和Java EE员工在Java中使用动态代理。