声明为 final 的方法导致 @EJB 为空,为什么?
Method declared as final causes @EJB to be null, why?
我有以下方法。当方法声明为 final
时,@EJB
为空。为什么会这样?当我省略 final
关键字时,它起作用了。
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class TokenService2
{
@EJB
private Configuration configuration;
public final void processAuthentication(String authCode) throws FileNotFoundException, IOException
{
//here configuration is NULL.
}
}
(配置本身就是单例)
Ejb bean 不喜欢任何其他方法修饰符,除了 public
用于业务方法(客户可调用的方法)。尽管这种特殊情况看起来像是 Wildfly 中的错误。 Wildfly 10 是 JavaEE7 兼容的,因此它的 EJB 容器应该符合 EJB 3.2 规范,该规范说明了以下关于会话 bean 的内容:
Only public methods of the bean class and of any superclasses except
java.lang.Object may be invoked through the no-interface view.
Attempted invocations of methods with any other access modifi- ers via
the no-interface view reference must result in the
javax.ejb.EJBException
因此您的业务方法无论如何都不能是最终的,但您的服务器应该会通知您。
.
我有以下方法。当方法声明为 final
时,@EJB
为空。为什么会这样?当我省略 final
关键字时,它起作用了。
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class TokenService2
{
@EJB
private Configuration configuration;
public final void processAuthentication(String authCode) throws FileNotFoundException, IOException
{
//here configuration is NULL.
}
}
(配置本身就是单例)
Ejb bean 不喜欢任何其他方法修饰符,除了 public
用于业务方法(客户可调用的方法)。尽管这种特殊情况看起来像是 Wildfly 中的错误。 Wildfly 10 是 JavaEE7 兼容的,因此它的 EJB 容器应该符合 EJB 3.2 规范,该规范说明了以下关于会话 bean 的内容:
Only public methods of the bean class and of any superclasses except java.lang.Object may be invoked through the no-interface view. Attempted invocations of methods with any other access modifi- ers via the no-interface view reference must result in the javax.ejb.EJBException
因此您的业务方法无论如何都不能是最终的,但您的服务器应该会通知您。 .