Even if I have different modules in my Java EE application including myproject-web and myproject-ejb; is it possible to call (or inject) my ejb session bean which is in the ejb module from a managed bean which is in the web module? When I asked before, I see the following declaration:
@EJB private BeanInterface yourbean
开发者_如何学编程
However, I wanna learn that whether it is possible or not, to call each other between different contexts (one of it in ejb context, the other one -managed bean- is in web context)?
Any help would be appreciated.
You can inject an @EJB
in a @ManagedBean
class, but not the other way round. If you'd like to execute the desired business logic in the EJB class, then you have to pass the managed bean instance as method argument yourselves.
@Stateless
public class EJB {
public void process(ManagedBean bean) {
// Business logic.
}
}
@ManagedBean
public class ManagedBean {
@EJB private EJB ejb;
public void submit() {
ejb.process(this);
}
}
If you really want this by all means, i guess you could try to write your own property resolver and inject by yourself(I didn't try).
I found out that it is impossible without writing your own resolver by now.. Thanks
精彩评论