The container will have to resolve all dependencies of the bean (instantiate them first) before instantiating the bean itself.
Now what truly happens when you invoke a method might differ...
You are using purely EJB here, there isn't any speck of CDI in your code!
@EJB
is an EJB annotation for dependency injection and @Stateless
is an EJB annotation for a "scope".
If you were to use CDI and had Weld as its implementation (all EE servers apart from tomee) then you would get lazy instantiation for any normal scoped beans. That would mean that you in fact inject an "empty" proxy object and it will only be instantiated upon first access.
Now, what I mean by CDI injection - use @Inject
instead of @EJB
.
You can still have your bean @Stateless
, CDI, if it's running in your app, then wraps it with it's own scope.
I also said that you need normal scoped beans - that means beans which use proxies.
Those are pretty much all CDI scopes except @Dependent
. Therefore it's @RequestScoped
, @SessionScoped
, @ApplicationScoped
. The dependencies of your bean would have to have those scopes to achieve lazy init.