|
Hi All, Is it not possible looking up the datasource in a session bean’s constructor? Let’s say I have a simple hello world session
beam and trying to lookup the datasource in the bean
constructor as follows. public HelloWorldBean() throws CreateException
{
try { Context
jndiCntx = new InitialContext(); DataSource
ds = (DataSource) jndiCntx.lookup("java:comp/env/xmeta_defaultDS");
} catch (Exception e) {
String msg = e.getMessage(); throw new CreateException(msg);
} } It doesn’t work and throwing following
exception javax.naming.NameNotFoundException: comp/env/xmeta_defaultDS at org.apache.geronimo.naming.java.RootContext.lookup(RootContext.java:45) at javax.naming.InitialContext.lookup(InitialContext.java:361) at ejb.demo.HelloWorld.<init>(HelloWorld.java:38) at ejb.demo.HelloWorld$$FastClassByCGLIB$$95ed802d.newInstance(<generated>) at net.sf.cglib.reflect.FastClass.newInstance(FastClass.java:91) at org.openejb.EJBInstanceFactoryImpl.newInstance(EJBInstanceFactoryImpl.java:76) at org.openejb.sfsb.StatefulInstanceContextFactory.newInstance(StatefulInstanceContextFactory.java:119) at org.openejb.sfsb.StatefulInstanceFactory.createInstance(StatefulInstanceFactory.java:86) at org.openejb.sfsb.StatefulInstanceInterceptor.getInstanceContext(StatefulInstanceInterceptor.java:144) at org.openejb.sfsb.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:92) at org.openejb.transaction.ContainerPolicy$TxNotSupported.invoke(ContainerPolicy.java:89) at org.openejb.transaction.TransactionContextInterceptor.invoke(TransactionContextInterceptor.java:80) at org.openejb.SystemExceptionInterceptor.invoke(SystemExceptionInterceptor.java:82) at org.openejb.GenericEJBContainer.invoke(GenericEJBContainer.java:238) at org.openejb.server.ejbd.EjbRequestHandler.invoke(EjbRequestHandler.java:297) at org.openejb.server.ejbd.EjbRequestHandler.doEjbHome_CREATE(EjbRequestHandler.java:342) at org.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:205) at org.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:150) at org.openejb.server.ejbd.EjbServer.service(EjbServer.java:87)
at
org.openejb.server.ejbd.EjbServer$$FastClassByCGLIB$$d379d2ff.invoke(<generated>) at net.sf.cglib.reflect.FastMethod.invoke(FastMethod.java:53) at org.apache.geronimo.gbean.runtime.FastMethodInvoker.invoke(FastMethodInvoker.java:38) at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:118) at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:800) at org.apache.geronimo.gbean.runtime.RawInvoker.invoke(RawInvoker.java:57) at org.apache.geronimo.kernel.basic.RawOperationInvoker.invoke(RawOperationInvoker.java:36) at
org.apache.geronimo.kernel.basic.ProxyMethodInterceptor.intercept(ProxyMethodInterceptor.java:96) at org.activeio.xnet.ServerService$$EnhancerByCGLIB$$fa602305.service(<generated>) at org.activeio.xnet.ServicePool$2.run(ServicePool.java:67) at org.activeio.xnet.ServicePool$3.run(ServicePool.java:90) at
org.apache.geronimo.pool.ThreadPool$ContextClassLoaderRunnable.run(ThreadPool.java:138) at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(Unknown
Source) at java.lang.Thread.run(Thread.java:570) This is my openejb-jar.xml <?xml
version="1.0"?> <openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar"
configId="ejb-Demo" parentId="geronimo/j2ee-server/1.0/car"> <enterprise-beans>
<session>
<ejb-name>HelloWorld</ejb-name>
<jndi-name>HelloWorld</jndi-name>
<resource-ref>
<ref-name>xmeta_defaultDS</ref-name>
<resource-link>jdbc/ASBDataSource</resource-link>
</resource-ref> </session> </enterprise-beans> </openejb-jar> If I call the datasource
lookup in a method other than constructor it works fine. What would you suggest to solve this
problem? This works fine with WebSphere
application server if I call the datasource lookup in
the constructor. Thanks, Siraj |
- Looking up the datasource in a session bean constructor Siraj Mohamed
