On Mar 31, 2009, at 11:26 AM, David Blevins wrote:
Construct the InitialContext() with the factory
org.apache.openejb.client.LocalInitialContextFactory. Creating an
no-arg InitialContext in a webapp will give you the spec defined
java:comp/env namespace which only contains the entries you
explicitly have declared via @EJB in a servlet, filter, listener,
etc. or via an <ejb-local-ref> entry in the web.xml
That's not quite a full explanation. In a javaee app new
InitialContext() will give you the geronimo jndi tree which has a
"global" part with stuff like the transaction manager and all your
datasources bound into it, and also the java:comp component-specific
javaee tree (which will include the @EJB or xml dd specified ejb refs).
Apparently the ejbs are bound in a different unrelated global jndi
context. Personally I consider this a bug.
thanks
david jencks
-David
On Mar 31, 2009, at 7:09 AM, Maarten Billemont wrote:
Hey,
I'm using Wicket for my web framework; and I'm trying to get my
EJBs injected into my Wicket code.
My issue has very little to do with Wicket, though.
I basically have an EJB in my.jar which is picked up by OpenEJB and
bound in the JNDI; and I'd like to access it from my.war (my Wicket
application).
So I do this from my-war:
ic = new InitialContext();
myBeanProxy = (MyBeanLocalInterface)
ic.lookup(MyBeanLocalInterface.class.getName());
This however fails with this in the logs:
15:35:06,308 INFO [OpenEJB] Auto-deploying ejb
my.group.my.ejb.MyBeanLocalInterface: EjbDeployment(deployment-
id=my.jar/my.group.my.ejb.MyBeanLocalInterface)
15:35:06,320 INFO [config] Loaded Module: my.group/my-deploy/1.0-
SNAPSHOT/ear
15:35:09,095 INFO [startup] Assembling app: /usr/local/share/
geronimo-jetty6-javaee5-2.1.3/var/temp/geronimo-
deploymentUtil7334128487386261603.jar
15:35:09,126 INFO [startup]
Jndi(name=my.group.my.ejb.MyBeanLocalInterface) --> Ejb(deployment-
id=my.jar/my.group.my.ejb.MyBeanLocalInterface)
15:35:09,126 INFO [startup] Created Ejb(deployment-id=my.jar/
my.group.my.ejb.MyBeanLocalInterface, ejb-
name=my.group.my.ejb.MyBeanLocalInterface, container=Default
Stateless Container)
15:35:16,824 ERROR [JavaEEInjectionListener] Unexpected Error
javax.naming.NameNotFoundException:
my.group.my.ejb.MyBeanLocalInterface
at
org
.apache
.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:
169)
at
org
.apache
.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:
603)
at javax.naming.InitialContext.lookup(InitialContext.java:409)
at
my
.group
.my
.view
.JavaEEInjectionListener
.onInstantiation(JavaEEInjectionListener.java:107)
Here's my setup:
my.ear (artifactId my-deploy)
|
|- my.war (artifactId my-view, contains my.group.my.view.*)
|
|- my.jar (artifactId my-controller contains my.group.my.ejb.*)
|
|- META-INF/application.xml
\- META-INF/geronimo-application.xml
my.ear/application.xml:
<module>
<web>
<web-uri>my.war</web-uri>
<context-root>/</context-root>
</web>
</module>
<module>
<ejb>my.jar</ejb>
</module>
<library-directory>lib/</library-directory>
my.ear/geronimo-application.xml:
<dep:environment>
<dep:moduleId>
<dep:groupId>my.group</dep:groupId>
<dep:artifactId>my-deploy</dep:artifactId>
<dep:version>1.0-SNAPSHOT</dep:version>
<dep:type>ear</dep:type>
</dep:moduleId>
</dep:environment>
my.war/geronimo-web.xml:
<dep:environment>
<dep:moduleId>
<dep:groupId>my.group</dep:groupId>
<dep:artifactId>my-view</dep:artifactId>
<dep:version>1.0-SNAPSHOT</dep:version>
</dep:moduleId>
</dep:environment>
<context-root>/</context-root>
my.jar/openejb-jar.xml:
<properties>
openejb.jndiname.format = {interfaceClass}
</properties>