CDI如何删除有状态会话bean? [英] How does CDI remove stateful session bean?

查看:76
本文介绍了CDI如何删除有状态会话bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该规范指出,当作用域的上下文即将被破坏时,CDI容器将删除SFSB。如何准确删除EJB?

The spec says that CDI container removes a SFSB when the scope's context is about to be destroyed. How does it exactly remove the EJB? It does not seem to be calling the method annotated with @Remove.

@Stateful
public class CustomerDAOImpl implements CustomerDAO {
    @PreDestroy
    public void onDestroy() {
        //This is getting called as expected
    }
    @Remove
    public void deleteMyBean() {
        //This is not getting called!
    }
}

因此,CDI从技术上说是按照规范说的做。问题是如何设法让EJB容器删除实例?谢谢。

So, CDI is technically doing what the spec says. The question is how is it managing to ask the EJB container to remove the instance? Thanks.

推荐答案

正如契约者所说,这是使用特定于实现的EJB API来完成的,它不是EJB标准API的一部分

As covener says this is done using an implementation specific EJB API, that isn't part of the EJB standard API.

正如盟友所说,调用@Remove并不是正确的操作方式。 @Remove方法由用户代码和EJB容器 tell 调用以删除EJB。如果要在删除EJB时进行回调,请使用@PreDestroy。

As covener says, calling @Remove is NOT the right way to proceed. @Remove methods are called by users code, and tell the EJB container to remove the EJB. If you want a callback when the EJB is removed, use @PreDestroy.

这篇关于CDI如何删除有状态会话bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆