1

I am using EJB3.0, Weblogic 11g

I am trying to do simple lookup from servlet to Statelessbean and run there a method. both under the same EAR. I managed to do it with Jboss. but I know that in Weblogic it's little bit diffrent so I channged my code and this is what I am doing and still no success:

The interface I have declared:

 @Local
 public interface OperatorBlockBeanLocal
 {
    public void testme();

 }

This is the class which implements the Interface:

@Stateless
@Local{ OperatorBlockBeanLocal.class })


@JNDIName(value = "OperatorBlockBean")


 public class OperatorBlockBean implements OperatorBlockBeanLocal
 {
    public void testme()
 {
    System.out.println("OperatorBlockBean");
 }
 }

And this is the servlet which trying to lookup the bean I decalred before:

try
    {
        context = new InitialContext();

        operatorBlockBean = (OperatorBlockBeanLocal) context
                .lookup("java:comp/env/OperatorBlockBean");
        operatorBlockBean.testme();
    } catch (NamingException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

Ofcourse that I get NamingException. anyone has any idea?

thanks, ray.

rayman
  • 20,786
  • 45
  • 148
  • 246

1 Answers1

0

Try using

@Stateless(mappedName="OperatorBlockBean")
@Local{ OperatorBlockBeanLocal.class }
public class OperatorBlockBean implements OperatorBlockBeanLocal

You can also use EJB injection in your servlet and not do a lookup. Here's how:

@EJB OperatorBlockBeanLocal operatorBlockBean;

The EJB will injected so you don't have to do a lookup.

Jeff West
  • 1,563
  • 9
  • 11
  • 1
    Is my lookup address right? coz it doesnt work with loop up. this is the errpr: While trying to look up comp/env/OperatorBlockBean in /app/webapp/SBNWeb/10178340.; remaining name 'comp/env/OperatorBlockBean' – rayman Apr 10 '11 at 07:05
  • Now I must do lookup coz I am outside of my container. any idea how to do that? – rayman May 11 '11 at 16:52