开发者

Calling a method on Session Bean from POJO?

开发者 https://www.devze.com 2023-04-02 22:34 出处:网络
Given only the fully qualified class name/interface name of开发者_运维技巧 the Session Bean, is it possible to instantiate call a method on it from a POJO?

Given only the fully qualified class name/interface name of开发者_运维技巧 the Session Bean, is it possible to instantiate call a method on it from a POJO?

If yes, how?

Thanks, TheLameProgrammer


Since EJB3.0 a session bean is a POJO as well, so you could instatiate it as any other class by

MyEJB ejb = new MyEJB();

But as Peter Lawrey pointed out correctly, this should be done by an application server.

In order to answer your question, you should provide more details, what you plan to do and what you have come up with so far.

PS: And allthough you name yourself lame, you should work on your accept rate...


see Accessing Enterprise Beans

Accessing Local Enterprise Beans Using the No-Interface View Client access to an enterprise bean that exposes a local, no-interface view is accomplished through either dependency injection or JNDI lookup.

To obtain a reference to the no-interface view of an enterprise bean through dependency injection, use the javax.ejb.EJB annotation and specify the enterprise bean’s implementation class:

@EJB
ExampleBean exampleBean;

To obtain a reference to the no-interface view of an enterprise bean through JNDI lookup, use the javax.naming.InitialContext interface’s lookup method:

ExampleBean exampleBean = (ExampleBean)
InitialContext.lookup("java:module/ExampleBean");
exampleBean.yourMethod();
0

精彩评论

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