Java 将无状态会话Bean注入异常侦听器?

Java 将无状态会话Bean注入异常侦听器?,java,glassfish,ejb,interceptor,Java,Glassfish,Ejb,Interceptor,我有一个异常拦截器,其工作原理如下: public class ExceptionInterceptor { @AroundInvoke public Object exceptionHandler(InvocationContext ctx) throws Exception { try { return ctx.proceed(); } catch (RuntimeException re) {

我有一个异常拦截器,其工作原理如下:

public class ExceptionInterceptor
{
    @AroundInvoke
    public Object exceptionHandler(InvocationContext ctx) throws Exception
    {
        try {
            return ctx.proceed();
        } catch (RuntimeException re) {
            // Log Exception Here

            throw re;
        }
    }
}
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;
        }
    }
}
是否有方法注入LogManagerBean,以便我可以执行以下操作:

public class ExceptionInterceptor
{
    @AroundInvoke
    public Object exceptionHandler(InvocationContext ctx) throws Exception
    {
        try {
            return ctx.proceed();
        } catch (RuntimeException re) {
            // Log Exception Here

            throw re;
        }
    }
}
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;
        }
    }
}

LogManagerBean被标记为
@Stateless
@LocalBean

我认为这是可能的。与其他拦截器一样。拦截器是在创建EJB实例的同时创建的,并且在调用EJB的第一个方法之前注入依赖项。

Wow。我不知道我一开始做错了什么,但我又试了一次,效果很好。奇怪的谢谢