Reputation: 21
as openejb documentation decalres
The unbreakable rules. Read these over and over again when things don't work.
i'm using openejb in embedded mode, DI is working fine, but i want to make lookup in pojo to get a reference to my Data Source using the standard jndi lookup as ctx.lookup("java:comp/env/DS") i tried to declare resources via xml and @Resource in a stateless ejb just to test if the env subcontext is populated but i don't know why the env subcontext is never created ... plz help
Upvotes: 2
Views: 2416
Reputation: 868
I had similar issues when I was using OpenEJB in tests. In case of embedded tests with OpenEJB you should rather look for java:openejb/ not java:comp/env
With this little snippet you can list what's registered by OpenEJB
NamingEnumeration<Binding> list = initialContext.listBindings("java:openejb/");
while (list.hasMore()) {
Binding item = list.next();
System.out.println(item.getClassName() +" :: " + "java:openejb/" + item.getName());
}
if you want to get to your datasource list everything registered under "java:openejb/PersistenceUnit/". most probably you will find "java:openejb/PersistenceUnit/[name-of-persistence-unit] [hashcode]" - whicho you can use later on - in a test.
hope that helps --Jakub
Upvotes: 5