Hallo cold80@libero.it,
> I was trying the first EJB example of the book "Mastering Enterprise
> Java Beans". After building the bean and deploying it successfully I
[quoted text clipped - 9 lines]
> }
> }
I expect Hello ist your BusinessInterface. But the lookup only returns the
HomeInterface. AFAIK you have to do the following
Object o = new InitialContext().lookup("HelloBean");
HelloHome home = (HelloHome) PortableRemoteObject.narrow(o,
HelloHome.class);
HelloRemote remote = home.create();
With this i expect you deployed your bean under the name "HelloBean".
> But I found many problems using the lookup method. Using the full
> "path" for the interface "examples.session.stateless.Hello", as
> specified in the book, I got
>
> Exception in thread "main" javax.naming.NameNotFoundException:
> examples.session.stateless.Hello not bound
Because the bean is not bound under that name (see META-INF/ejb-jar.xml for
details).
> Otherwise, using the line
>
[quoted text clipped - 5 lines]
> org.jnp.interfaces.NamingContext cannot be cast to
> examples.session.stateless.Hello
Because you don't get a Hello instance. It's a home interface you get.
> So I think I was grabbing the wrong object from JBoss. Looking on many
> posts and web pages I found that using
[quoted text clipped - 4 lines]
> understand the way JNDI is naming my resources...can you give me
> informations about that? It would be really appreciated...
JNDI is a way to bind a name to a class and get a remote (or local) instance
of this class. The EJB spec requires the definition of a deployment
descriptor file ejb-jar.xml. Here you can define the bean environment
(jndi-name, home class, remote class etc.). The container reads this file
and configures your beans. So you have a defined way for accessing your
beans.
Cheers
Per
cold80@libero.it - 05 Feb 2007 08:23 GMT
I didn't mentioned that my example is developed using EJB 3.0. Maybe
the container is defining the local and remote interfaces for me, but
I just define a interface as
package examples.session.stateless;
public interface Hello {
public String hello();
}
and a class implementation
package examples.session.stateless;
import javax.ejb.Stateless;
import javax.ejb.Remote;
@Stateless
@Remote(Hello.class)
public class HelloBean implements Hello{
public String hello(){
System.out.println("hello()");
return "Hello world!!!";
}
}
So, as you see, I'm not using ejb-jar.xml file to define the
informations needed by the container. Intead I'm writing annotations
on the code. Do you think I have to write the ejb-jar.xml file as
well? I mean, is it because I didn't write it that I can't access it?
Do you know where I can find informations about this matter on the
Internet (specific for Jboss, actually)?
Thank you again for your help
Cold
Per Newgro ha scritto:
> Hallo cold80@libero.it,
>
[quoted text clipped - 57 lines]
> Cheers
> Per
Per Newgro - 05 Feb 2007 10:38 GMT
Hallo cold80@libero.it,
> I didn't mentioned that my example is developed using EJB 3.0.
Aha.
> Maybe the container is defining the local and remote interfaces for me,
> but I just define a interface as
[quoted text clipped - 4 lines]
> public String hello();
> }
In ejb-3.0 spec the "default" for the business interface (here Hello) is
@Local. U have to specify it as @Remote
> and a class implementation
>
[quoted text clipped - 11 lines]
> }
> }
The @Remote annotation is afaik not required if you added it to Hello.
> So, as you see, I'm not using ejb-jar.xml file to define the
> informations needed by the container. Intead I'm writing annotations
> on the code. Do you think I have to write the ejb-jar.xml file as
> well?
Nope. Benefit of EJB3 is afaik the simplification of deployment to. SO
ejb-jar.xml is not required (but possible)
> I mean, is it because I didn't write it that I can't access it?
> Do you know where I can find informations about this matter on the
> Internet (specific for Jboss, actually)?
I strongly recommend you to read the ejb-3.0 spec. It's realy simple to
read. After this much of the new concepts are clear. Trust me.
You can download it here:
http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html
Tell me if problems still occur.
Cheers
Per