开发者

By using ejb 3 , jsf and jboss is it possible to call an EJB method from web module?

开发者 https://www.devze.com 2022-12-28 19:05 出处:网络
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 b

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

0

精彩评论

暂无评论...
验证码 换一张
取 消