每次在 servlet 上完成请求时,EJB 都会注入到 servlet 上吗?

发布于 2024-12-23 09:37:57 字数 217 浏览 3 评论 0原文

我正在尝试复制 MVC 设计模式。这就是我所做的,我有一个处理所有请求的 servlet。其中,是注入的ejb。因此,在此控制器/Servlet 中使用 @EJB 注释声明了 7 到 15 个 ejb。

我只想问,例如,1 个用户是否调用主控制器/servlet。 ejb 是否仅在该调用时被注入,或者每次用户调用 servlet 时它们每次都会被注入吗?或者第一次创建 servlet 时注入 ejb?

I am trying to copy the MVC design pattern. And this is what I do, I have a servlet which handles all the requests. In it, are the injected ejbs. So in this controller/servlet is declared 7 to 15 ejbs with the @EJB annotations.

I just want to ask if for example, 1 user calls the maincontroller/servlet. do the ejbs get injected only on that call or everytime a user calls the servlet do they get injected everytime? or the ejbs are injected the first time the servlet is created?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

開玄 2024-12-30 09:37:57

注入是在创建对象时完成的,并且由于 Servlet 容器通常(但不是强制性的 - 在单线程模型的情况下)创建 servlet 的单个实例,然后在单独的线程中服务请求,因此您的情况下的 EJB 应该在如果您没有使用 SingleThreadModel。

Injection is done when creating the object and since Servlet Container usually (but not mandatory - in case of single thread model) creates a single instance of a servlet and then serves the request in separate thread, the EJB in your case should be created once in case you are not using SingleThreadModel.

依 靠 2024-12-30 09:37:57

资源在对象创建时注入(因为您不能注入静态字段,而只能注入成员变量)。

对于 servlet,servlet 类由 servlet 容器加载,然后创建一个实例。此时,@EJB或@Resource被注入。然后容器调用 init() 方法

Resources are injected at the time of object creation ( since you cannot inject into static fields, but just member variables ).

In the case of a servlet, the servlet class is loaded by the servlet container and then an instance is created. At this time, the @EJB or @Resource is injected. The container then calls the init() method

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文