![](/img/trans.png)
[英]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.