On Apr 23, 2008, at 12:37 AM, Alexander von Hedenström wrote:
Hi!
Thank you, this helped me a lot. The problem was this:
2008/4/22 David Blevins <[EMAIL PROTECTED]>:
Technically, we'll look for a Resource with id "jdbc/Orange" first,
but
not finding that we'll scrape off the prefix and look for a
Resource with
"Orange" as the id. With the above ref you should be able to look
up the
datasource in the bean that declared it as follows:
InitialContext context = new InitialContext();
DataSource dataSource = (DataSource)
context.lookup("java:comp/env/jdbc/Orange");
I just looked in the wrong context. In my test servlet however, I
found the
home object of my EJB by asking for:
Properties p = *new* Properties();
p.put("java.naming.factory.initial",
"org.openejb.client.RemoteInitialContextFactory");
javax.naming.InitialContext ctx = *new*
javax.naming.InitialContext(p);
Object obj = ctx.lookup("/MyRemoteHome");
No java:comp/env here! This works on the servlet side to find the
bean, but
not for the bean itself to find the data source.
Hehe. That would be an issue, yes :)
Just as a note, if you're using Tomcat and OpenEJB together via the
openejb.war file, you can use Java EE 5 annotations in your Servlets
to reference your EJBs.
At simplest in your Servlet you can do:
@EJB private MyBeanInterface myBean;
If you have more than one bean with "MyBeanInterface", then you can:
@EJB(beanName="theEjbNameOfYourBean")
private MyBeanInterface myBean;
-David