无法使用Spring JNDIObjectfactorybean查找jboss 7.x中配置的数据源

时间:2014-04-08 13:41:02

标签: spring jboss jboss7.x datasource jndi

我在Jboss 7.x中配置了数据源,如下所示:

 <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>

然后在我的spring应用程序中,我使用下面的代码来查找数据源:

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

但是当我部署应用程序时,我得到以下异常:

  

CreationException:使用名称&#39; jndiDataSource&#39; 创建bean时出错   在ServletContext资源[/WEB-INF/applicationContext.xml]中定义:   调用init方法faile 嵌套异常是   * javax.naming.NameNotFoundException:查找错误 *    jboss / datasources / MyWebAppDS,服务服务   * jboss.naming.context.java.jboss.datasources.MyWebAppDS未启动 *           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)   [弹簧豆-3.1。 ELEASE.jar:3.1.1.RELEASE]           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)   [spring-beans-3.1.1.R ASE.jar:3.1.1.RELEASE]           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)   [spring-beans-3.1.1.REL E.jar:3.1.1.RELEASE]           在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:294)   [弹簧豆-3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)   [弹簧豆-3.1.1.RELEASE.jar:3   1.RELEASE]           在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)   [弹簧豆-3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)   [弹簧豆-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]           在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)   [spring-context-3.1.1.RE SE.jar:3.1.1.RELEASE]           在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)   [弹簧网络3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)   [弹簧网络3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)   [弹簧网络3.1.1.RELEASE.jar:3.1.1.RELEASE]           at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3339)   [jbossweb-7.2.0.Final-红帽-1.jar:7.2.0.Final-红帽-1]           在org.apache.catalina.core.StandardContext.start(StandardContext.java:3777)   [jbossweb-7.2.0.Final-红帽-1.jar:7.2.0.Final-红帽-1]           在org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:156)   [JBoss的-AS-web的7.2.0.Final-红帽-8.jar:7.2.0.Final-红帽-8]           在org.jboss.as.web.deployment.WebDeploymentService.access $ 000(WebDeploymentService.java:60)   [JBoss的-AS-web的7.2.0.Final-红帽-8.jar:7.2.0.Final-红帽-8]           在org.jboss.as.web.deployment.WebDeploymentService $ 1.run(WebDeploymentService.java:93)   [JBoss的-AS-web的7.2.0.Final-红帽-8.jar:7.2.0.Final-红帽-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]           在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]           在java.lang.Thread.run(Thread.java:662)[rt.jar:1.6.0_24]           at org.jboss.threads.JBossThread.run(JBossThread.java:122)引起:javax.naming.NameNotFoundException:查找错误   jboss / datasources / MyWebAppDS,服务服务   jboss.naming.context.java.jboss.datasources.MyWebAppDS没有启动           在org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:132)           在org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:80)           在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)           在org.jboss.as.naming.InitialContext.lookup(InitialContext.java:120)           在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:183)           在org.jboss.as.naming.NamingContext.lookup(NamingContext.java:179)           在javax.naming.InitialContext.lookup(InitialContext.java:392)[rt.jar:1.6.0_24]           在org.springframework.jndi.JndiTemplate $ 1.doInContext(JndiTemplate.java:154)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)   [弹簧上下文3.1.1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)   [弹簧豆-3.1。   1.RELEASE.jar:3.1.1.RELEASE]           在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)   [spring-beans-3.1.1.R ELEASE.jar:3.1.1.RELEASE]           ......还有24个

我在这里遗漏了什么吗?

1 个答案:

答案 0 :(得分:1)

我错过了导致无法启动JNDI服务的依赖项。 我添加了sqljdbc4.jar%jboss-home%\ modules \ system \ layers \ base \ com \ microsoft \ main这解决了我的问题。