1
在MyInterceptor
,哪個接口,Ifclocal
或IfcRemote
,調用方法doStuff
在MyEjb
?有可能知道你的bean被調用了哪個「通道」? 我需要知道哪個依賴注入調用了該方法。如何攔截java中的特定接口?
@Local
public interface IfcLocal {
void doStuff(String s);
}
@Remote
public interface IfcRemote {
void doStuff(String s);
}
@Stateless
@Interceptors({ MyInterceptor.class })
public class MyEjb implements IfcLocal, IfcRemote {
@Override
public void doStuff(String s) {
System.out.println(s);
}
}
public class MyManagedBean {
@EJB private ifcLocal ifcLocal;
@EJB private IfcRemote ifcRemote;
public void go() {
ifcLocal.doStuff("xxx");
ifcRemote.doStuff("xxx");
}
}
public class MyInterceptor {
@AroundInvoke
public Object intercept(InvocationContext inv) throws Exception {
// ??? who invoked ???
System.out.prinln(inv.getTarget().getClass()); // print MyEjb
}
}
爲什麼你需要知道這一點? – 2014-03-12 14:07:54
如果一個本地接口的方法,所以我可能要克隆一些參數。 –