如何在java工具中使用拦截器?

如何在java工具中使用拦截器?,java,interceptor,Java,Interceptor,是否可以在没有应用服务器的情况下使用拦截器(如仅在命令行工具中) 我尝试了以下操作,但没有看到任何输出: import javax.interceptor.AroundInvoke; import javax.interceptor.InvocationContext; public class PerformanceInterceptor { @AroundInvoke Object measureTime(InvocationContext ctx) throws Exce

是否可以在没有应用服务器的情况下使用拦截器(如仅在命令行工具中)

我尝试了以下操作,但没有看到任何输出:

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
    }
}
可能有什么问题?

请检查以下示例:。顺便说一句,很好的JavaEE6特性


如果没有EJB和Java,EE员工在Java中使用动态代理。

这如何回答“在没有应用服务器的情况下使用[…]?”的问题?我认为它们只适用于EJB,而不适用于“普通”Java类。