我创建了以下调用类,当调用被拦截的方法时,应该调用它:
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@Interceptor
class TestAspect {
@AroundInvoke
public Object log(InvocationContext context) throws Exception {
System.out.println("AroundInvoke method called");
return context.proceed();
}
}
Run Code Online (Sandbox Code Playgroud)
和这个资源:
import javax.interceptor.Interceptors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@Path("/test")
@Interceptors(TestAspect.class)
public class TestResource {
@GET
@Path("/")
public String test() {
System.out.println("Resource method called");
return new String("test");
}
}
Run Code Online (Sandbox Code Playgroud)
但我只从资源中获取日志行。
| 归档时间: |
|
| 查看次数: |
568 次 |
| 最近记录: |