EJB在PreProcessInterceptor中为null

xxx*_*xxx 5 java jboss ejb java-ee interceptor

我在JBoss AS 7.1.1环境中使用RestEasy.

我出于安全原因实现了一个PreProcessInterceptor类.该类使用@Provider和@ServerInterceptor进行注释.每次都会调用拦截器,这很好.

现在,困扰我的是以下几点.

我将带有@EJB注释的EJB注入到类中.调用PreProcessInterceptor时,表示EJB始终为null.

@Provider
@ServerInterceptor
public class SecurityInterceptor implements PreProcessInterceptor
{
    @EJB
    private SomeEjb someEjbServiceFacade;

    ... some funny stuff
}
Run Code Online (Sandbox Code Playgroud)

EJB看起来像是:

@Stateless
public class SomeEjb extends AbstractServiceFacade
{
    ... some important stuff
}
Run Code Online (Sandbox Code Playgroud)

有趣的部分,它通过查找工作:

Context ctx = new InitialContext();
SomeEjb asf = ( SomeEjb )ctx.lookup("java:global/mySuperApplication/SomeEjb" );
Run Code Online (Sandbox Code Playgroud)

有人对此行为有解释吗?

提前致谢.

Sza*_*pul 0

尝试将@Stateless注释添加到您的SecurityInterceptor类中。