I have an Exception Interceptor that works like this:
public class ExceptionInterceptor
{
@AroundInvoke
public Object exceptionHandler(InvocationContext ctx) throws Exception
{
try {
return ctx.proceed();
} catch (RuntimeException re) {
// Log Exception Here
throw re;
}
}
}
Is there a way to inject a LogManagerBean so I can do something like this:
public class ExceptionInterceptor
{
@EJB
LogManagerBean logManager;
@AroundInvoke
public Object exceptionHandler(InvocationContext ctx) throws Exception
{
try {
return ctx.proceed();
} catch (RuntimeException re) {
// Log Exception Here
logManager.error(re);
throw re;
}
}
}
The LogManagerBean is marked @Stateless
and @LocalBean
.
I think it's possible. As in the case of other interceptors. Interceptors is created at the same time as the EJB instance is created, and dependency is injected before calling the first method of EJB.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.