2 Replies Latest reply on Mar 29, 2012 9:55 AM by Stephen Coy

    JBoss datasource JNDI lookup through Spring issue

    Jon Fox Newbie

      I am trying to locate the default ExampleDS datasource present in standalone.xml using JNDI via the Spring framework.

       

      The relevant portion of my Spring context for the datasource is as follows:

       

      <jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/ExampleDS"

              expected-type="javax.sql.DataSource" environment-ref="jndiProperties">

      </jee:jndi-lookup>

       

      <util:properties id="jndiProperties" location="classpath:jndi.properties" />

       

      and the jndi.properties is as follows:

       

      java.naming.provider.url=remote://localhost:4447

      java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory

      java.naming.security.principal=somename

      java.naming.security.credentials=somepassword

       

      However, on deploying the WAR on JBoss AS 7.1.Final, I get the following exception:

       

      16:24:42,577 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/JobConsumer]] (MSC service thread 1-4) Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: jboss/datasources/ExampleDS -- service jboss.naming.context.java.jboss.exported.jboss.datasources.ExampleDS

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567) [org.springframework.beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) [org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) [org.springframework.context-3.1.1.RELEASE.jar:3.1.1.RELEASE]

              at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245) [spring.jar:2.0.7]

              at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188) [spring.jar:2.0.7]

              at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49) [spring.jar:2.0.7]

              at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.10.Final.jar:]

              at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.10.Final.jar:]

              at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_21]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_21]

              at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_21]

      Caused by: javax.naming.NameNotFoundException: jboss/datasources/ExampleDS -- service jboss.naming.context.java.jboss.exported.jboss.datasources.ExampleDS

              at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97) [jboss-as-naming-7.1.0.Final.jar:7.1.0.Final]

              at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:177) [jboss-as-naming-7.1.0.Final.jar:7.1.0.Final]

              at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:124) [jboss-client-7.1.0.Final.jar:7.1.0.Final]

              at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:70) [jboss-client-7.1.0.Final.jar:7.1.0.Final]

              ... 3 more

       

      I tried to use a different datasource name containing 'exported' ("java:jboss/exported/datasources/ExampleDS") but it still gives the same exception and the WAR fails to deploy. I have also tried giving the jndi-name as "datasources/ExampleDS" in Spring's application context. What's wrong?

       

      PS: I intend to enable JNDI access of datasources and accessor applications may not be on the same system as the one hosting JBoss.  Thanks!