[英]Java - Interface - How do I assign a specific interface in multiple activities all together
[英]How do intercept specific interface in java?
在MyInterceptor
,哪個接口Ifclocal
或IfcRemote
調用了MyEjb
doStuff
方法? 可能知道通過哪個“渠道”調用了您的bean? 我需要知道哪個依賴項注入調用了該方法。
@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
}
}
注入@Resource private SessionContext sessionContext;
在MyInterceptor
。 之后: Class<?> interfaceReference = sessionContext.getInvokedBusinessInterface()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.