tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bård Magnus Kvalheim" <mag...@kvalheim.eu>
Subject Re: JNDI lookup NameNotFoundException
Date Tue, 13 May 2008 21:58:31 GMT
My little test was finally a success!

For my setup I have (names abbreviated):

*common.jar *
This library have the Local and Remote interfaces

*core.war*
Collapsed war which implements Local and Remote interfaces and creates EJB3
bean

*client.war*
uses ejb beans configured through spring


*Classloading issue*
Initially I included the common.jar in both of my war files. Doing this I
got ClassCastException trying to cast EJB to interface.
I realized that this could be related to Classloading conflicts.
Reading a previous post by David in the developer mailing list I found that
OpenEJB will load the ejb's in Tomcat's common classloader.
So I removed common.jar from the war's lib and moved it into tomcat's
common/lib. That resolved the Classloading issue.
(Please let me know if there is an alternative approach to this as it adds
complexity to deployment)


*Spring configuration*
In my client.war I took David's suggestion and configured jndiEnvironment.
<bean id="calculator"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="CalculatorLocal"/>
        <property name="jndiEnvironment">
            <props>
                <prop key="java.naming.factory.initial">
                    org.apache.openejb.client.LocalInitialContextFactory
                </prop>
            </props>
        </property>
</bean>

I've used JndiObjectFactoryBean in this example, but
LocalStatelessSessionProxyFactoryBean could also be used.


Thanks David for your help. I'm sure something new will come up shortly
though ;-)

//magnus


In my setup

2008/5/13 David Blevins <david.blevins@visi.com>:

>
> On May 13, 2008, at 2:26 AM, Bård Magnus Kvalheim wrote:
>
>  Hi David, thanks for you reply.
> >
> > My comments below...
> >
> > 2008/5/13 David Blevins <david.blevins@visi.com>:
> >
> >
> > > On May 11, 2008, at 4:03 PM, Bård Magnus Kvalheim wrote:
> > >
> > > Hi,
> > >
> > > >
> > > > I'm new to ejb and just started experimenting with openejb tomcat
> > > > plugin
> > > > Tomcat: 5.5.26
> > > > OpenEJB 3.0
> > > >
> > > >
> > > > So far the openejb plugin is looking good. Setup completed and I've
> > > > successfully deplyed the webapp example as well.
> > > >
> > > > I deployed my own war (Collapsed ear) containing a Stateless session
> > > > bean.
> > > > This is the same as the calculator example.
> > > >
> > > > The logs say:
> > > > 2008-05-12 00:12:09,700 - INFO - Jndi(name=CalculatorLocal) -->
> > > > Ejb(deployment-id=Calculator)
> > > > 2008-05-12 00:12:09,700 - INFO - Created
> > > > Ejb(deployment-id=Calculator,
> > > > ejb-name=Calculator, container=My Stateless Container)
> > > >
> > > > Browing the OpenEJB JNDI Namespace Browser I can see my ejb, but I
> > > > get
> > > > FAIL
> > > > when I try to inspect. (The ejb's from webapp example is also shown
> > > > and
> > > > fail
> > > > just the same way, so perhaps this is expected).
> > > >
> > > >
> > > Fixing up that FAIL issue now, thanks!
> > >
> >
> >
> > Great! You guys work fast :-)
> >
> >
> > >
> > > Anyways, trying to use the bean in client app, which is another war in
> > >
> > > > same
> > > > tomcat, I get "javax.naming.NameNotFoundException" no matter what I
> > > > do.
> > > >
> > > > I've tried jndi names:
> > > > Calculator
> > > > CalculatorLocal
> > > > java:comp/env/CalculatorLocal
> > > > java:comp/env/com.test.Calculator/CalculatorLocal
> > > >
> > > > I'm using spring's LocalStatelessSessionProxyFactoryBean on client
> > > > for
> > > > looking up ejb from jndi.
> > > >
> > > > Any thoughts on where I've gone wrong on this?
> > > >
> > > >
> > > Don't know how the LocalStatelessSessionProxyFactoryBean works, but
> > > you'll
> > > essentially need to make it do this:
> > >
> > > Properties jndiEnv = new Properties();
> > > jndiEnv.setProperty("java.naming.factory.initial",
> > > "org.apache.openejb.client.LocalInitialContextFactory");
> > >
> > > InitialContext context = new InitialContext(jndiEnv);
> > > context.lookup("CalculatorLocal");
> > >
> > >
> > Yes, this works as expected.
> > The problem must be with spring configuration.
> >
> >
> >
> > >
> > > Looks like the LocalStatelessSessionProxyFactoryBean has a method
> > > "setJndiEnvironment(Properties jndiEnvironment)" which might do the
> > > trick.
> > >
> >
> >
> > Thanks for pointing this out!
> > Will experiment and report back to this thread.
> >
>
> Great.  We can make a little doc for it and put it on the website.
>
> -David
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message