I'm currently puzzled with the way Glassfish 3.1.2.2 handles EJBs.
I have an OSGi project, which consists of many OSGi bundles (jars). Also, there are a few WARs, including a Tapestry web application.
In one such bundle, let's call it "interfaces.jar", I have an interface defined:
public interface MyInterface() {
public static final String JNDI_NAME = "java:global/MyInterface";
void myMethod();
}
The implementation of that interface is as following, and it's contained in bundle "beans.jar":
@Stateless
@EJB(name = MyInterface.JNDI_NAME, beanInterface = MyInterface)
public class MyBean implements MyInterface() {
void myMethod() {
...
}
}
I am calling it from my Tapestry WAR app via JNDI lookup:
InitialContext.doLookup(MyInterface.JNDI_NAME);
Now, I was reading EJB 3.1 specification, and it says that I can one of the following scenarios:
- Interface has @Local annotation; EJB is implementing this interface.
- Interface is a plain Java interface without annotation; EJB with @Local annotation is implementing it.
- Interface is a plain Java interface without annotation; EJB is implementing it.
- Interface is a plain Java interface without annotation; EJB with @Local annotation is not implementing it.
- EJB doesn’t have any special annotations.
So, by elimination:
- I don't have @Local on interface
- I don't have @Local on EJB
- Seems somewhat right
- I don't have @Local on EJB
- I have @EJB annotation on my EJB
So, it seems that it's case 3:
"Because it’s the only implemented interface of the EJB, a container assumes that it must be a local business interface."
Now, a few questions:
- Is my interface a local or remote one, since there is no local or remote annotation?
- If it is local, I should be able to inject it with
@EJB
annotation, but it fails? - If it's remote, it is not in compliance with the explanation a few lines above?
- If I add either
@Local
or@Remote
, and perform JNDI lookup, I get a naming exception and NPE telling me there is nothing under thatJNDI_NAME
. How is that possible? - What exactly does
@EJB(name = ..., beanInterface = ...)
do on bean class and how does it interact with@Local
and@Remote
annotations?
I'm currently puzzled with the way Glassfish 3.1.2.2 handles EJBs.
I have an OSGi project, which consists of many OSGi bundles (jars). Also, there are a few WARs, including a Tapestry web application.
In one such bundle, let's call it "interfaces.jar", I have an interface defined:
public interface MyInterface() {
public static final String JNDI_NAME = "java:global/MyInterface";
void myMethod();
}
The implementation of that interface is as following, and it's contained in bundle "beans.jar":
@Stateless
@EJB(name = MyInterface.JNDI_NAME, beanInterface = MyInterface)
public class MyBean implements MyInterface() {
void myMethod() {
...
}
}
I am calling it from my Tapestry WAR app via JNDI lookup:
InitialContext.doLookup(MyInterface.JNDI_NAME);
Now, I was reading EJB 3.1 specification, and it says that I can one of the following scenarios:
- Interface has @Local annotation; EJB is implementing this interface.
- Interface is a plain Java interface without annotation; EJB with @Local annotation is implementing it.
- Interface is a plain Java interface without annotation; EJB is implementing it.
- Interface is a plain Java interface without annotation; EJB with @Local annotation is not implementing it.
- EJB doesn’t have any special annotations.
So, by elimination:
- I don't have @Local on interface
- I don't have @Local on EJB
- Seems somewhat right
- I don't have @Local on EJB
- I have @EJB annotation on my EJB
So, it seems that it's case 3:
"Because it’s the only implemented interface of the EJB, a container assumes that it must be a local business interface."
Now, a few questions:
- Is my interface a local or remote one, since there is no local or remote annotation?
- If it is local, I should be able to inject it with
@EJB
annotation, but it fails? - If it's remote, it is not in compliance with the explanation a few lines above?
- If I add either
@Local
or@Remote
, and perform JNDI lookup, I get a naming exception and NPE telling me there is nothing under thatJNDI_NAME
. How is that possible? - What exactly does
@EJB(name = ..., beanInterface = ...)
do on bean class and how does it interact with@Local
and@Remote
annotations?
0 commentaires:
Enregistrer un commentaire