简体   繁体   中英

do EJBs get injected on a servlet everytime a request is done on the servlet?

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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