This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Websphere and the fly likes How to lookup a local interface for a session bean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "How to lookup a local interface for a session bean?" Watch "How to lookup a local interface for a session bean?" New topic
Author

How to lookup a local interface for a session bean?

Matt S Andersson
Greenhorn

Joined: May 14, 2009
Posts: 4

Hello.

I am trying out EJBs for the first time and i ran into a problem trying to lookup the local interface of a session bean.


My session EJB looks like this:

package model;

@Stateless
@Remote
@Local
public class SessionEJBBean implements SessionEJBLocal, SessionEJB {
...
}

The local interface:

package model;

@Local
public interface SessionEJBLocal {
...
}

And my remote interface (that i don't wish to use):

package model;

@Remote
public interface SessionEJB {
...
}

Now i have a simple test client where i would like to use the session bean. I tried this (among a few other ideas that didn't work):

@EJB(name = "model/SessionEJBBean", beanInterface = SessionEJBLocal.class)
public class SessionEJBClient1 {
public static void main(String [] args) {
try {
final Context context = getInitialContext();
Object ref = context.lookup("java:comp/env/model/SessionEJBBean");
SessionEJBLocal sessionEJB = (SessionEJBLocal) ref;
...
}

This fails with the error message: "javax.naming.NameNotFoundException: While trying to lookup 'java:comp.env/model/SessionEJBBean' didn't find subcontext 'java:comp'. Resolved '' [Root exception is javax.naming.NameNotFoundException: While trying to lookup 'java:comp.env/model/SessionEJBBean' didn't find subcontext 'java:comp'. Resolved '']; remaining name 'java:comp/env/model/SessionEJBBean'
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:234)"

Can someone please give me a hand here?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to lookup a local interface for a session bean?