1
votes

I have configured datasource in Jboss 7.x as below:

 <subsystem xmlns="urn:jboss:domain:datasources:1.1">
        <datasources>
            <datasource jndi-name="java:jboss/datasources/MyWebAppDS" pool-name="MyWebAppDS" enabled="true" use-java-context="true">
                <connection-url>jdbc:sqlserver://localhost:1433;database=sa1p</connection-url>
                <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
                <security>
                    <user-name>sa</user-name>
                    <password>sa1</password>
                </security>
            </datasource>
        </datasources>
    </subsystem>

then in my spring application I am using below code to look up datasource:

 <bean id="jndiDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:jboss/datasources/MyWebAppDS</value>
    </property>
</bean>

but when I deploy the application I get below exception:

CreationException: Error creating bean with name 'jndiDataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method faile nested exception is *javax.naming.NameNotFoundException: Error looking up* jboss/datasources/MyWebAppDS, service service *jboss.naming.context.java.jboss.datasources.MyWebAppDS is not started* at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455) [spring-beans-3.1. ELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [spring-beans-3.1.1.R ASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [spring-beans-3.1.1.REL E.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.1.RELEASE.jar:3 1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567) [spring-beans-3.1.1.RELEA jar:3.1.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) [spring-context-3.1.1.RE SE.jar:3.1.1.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) [spring-web-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3339) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1] at org.apache.catalina.core.StandardContext.start(StandardContext.java:3777) [jbossweb-7.2.0.Final-redhat-1.jar:7.2.0.Final-redhat-1] at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:60) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:93) [jboss-as-web-7.2.0.Final-redhat-8.jar:7.2.0.Final-redhat-8] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [rt.jar:1.6.0_24] at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_24] at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_24] at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_24] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_24] at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_24] at org.jboss.threads.JBossThread.run(JBossThread.java:122) Caused by: javax.naming.NameNotFoundException: Error looking up jboss/datasources/MyWebAppDS, service service jboss.naming.context.java.jboss.datasources.MyWebAppDS is no t started at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:132) at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:80) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197) at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:120) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183) at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179) at javax.naming.InitialContext.lookup(InitialContext.java:392) [rt.jar:1.6.0_24] at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187) [spring-context-3.1.1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) [spring-beans-3.1. 1.RELEASE.jar:3.1.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) [spring-beans-3.1.1.R ELEASE.jar:3.1.1.RELEASE] ... 24 more

Am i missing anything here ?

1

1 Answers

1
votes

I had missing dependencies which was causing failure to start JNDI service. I added sqljdbc4.jar %jboss-home%\modules\system\layers\base\com\microsoft\main which resolved my problem.