简体   繁体   English

将无状态会话Bean注入异常拦截器吗?

[英]Inject a Stateless Session Bean into an Exception Interceptor?

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: 有没有办法注入一个LogManagerBean,所以我可以做这样的事情:

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 . LogManagerBean标记为@Stateless@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. 在创建EJB实例的同时创建拦截器,并在调用EJB的第一个方法之前注入依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM