The easiest way is to just inject a reference the bean using EJB 3.0
@MessageDriven
public class FooMDB implements javax.jms.MessageListener {
@EJB
private BarLocal bar;
public void onMessage(Message m) {
...
bar.foobar();
}
See the Java EE 5 Tutorial for more examples :
http://java.sun.com/javaee/5/docs/tutorial/doc/
> The easiest way is to just inject a reference the
> bean using EJB 3.0
>
> @MessageDriven
> public class FooMDB implements
> javax.jms.MessageListener {
>
>@EJB
> private BarLocal bar;
>
>public void onMessage(Message m) {
>...
>
>bar.foobar();
>
> See the Java EE 5 Tutorial for more examples :
>
> http://java.sun.com/javaee/5/docs/tutorial/doc/
Thanks for your early reply.
But the problem with me is we are not using EJB3.0. I am totally new to EJB's and got assigned with this.
Please help me out.
Thanks,
Prakash
Hi Prakash,
If you're using J2EE 1.4 you can use the J2EE 1.4 tutorial instead :
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
The pre-EJB 3.0 approach for getting references to ejbs involves two things :
1) declaring the ejb-ref(for remote ejbs) or ejb-local-ref (for local ejbs) in the *client* component's deployment descriptor.
Here's an example :
<ejb-local-ref>
<ejb-ref-name>bar_ejbref</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.acme.BarLocalHome</local-home>
<local>com.acme.BarLocal</local>
<ejb-link>BarBean</ejb-link>
</ejb-local-ref>
2) looking up the dependency in the private component environment (java:comp/env)
InitialContext ic = new InitialContext();
BarLocalHome barLocalHome = (BarLocalHome) ic.lookup("java:comp/env/bar_ejbref");
Notice how the portion of the lookup string after "java:comp/env/" matches the name of the ejb-local-ref dependency (ejb-ref-name)
--ken