JNDI在JBoss 7.0.2中查找数据源导致NameNotFoundException

时间:2012-02-16 21:22:16

标签: jboss jndi

我在JBoss 7.0.2中对数据源的JNDI查找工作正常时遇到了一些问题。基本上,这个应用程序应该可以跨多个应用程序服务器进行部署,因此我希望遵循适当的标准。有问题的应用程序是一个部署在Liferay 6.1中的简单portlet应用程序,在Jboss托管域中运行;我在web.xml,jboss-web.xml和persistence.xml中尝试了各种命名约定组合;一切都无济于事。我目前的配置如下:

Spring persistence.xml:

<jee:jndi-lookup id="surveyDS" jndi-name="jdbc/surveyDS" resource-ref="true" />

的web.xml:

<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
    ...
    <resource-ref>
        <res-ref-name>jdbc/surveyDS</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
</web-app>

的JBoss-web.xml中:

<?xml version="1.0"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.4//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_4_0.dtd">
<jboss-web>
    <resource-ref>
        <res-ref-name>jdbc/surveyDS</res-ref-name>
        <jndi-name>java:jboss/datasources/surveyDS</jndi-name>
    </resource-ref>
</jboss-web>

$ {JBOSS_HOME} /domain/configuration/domain.xml中的数据源定义:

<datasource jndi-name="java:jboss/datasources/surveyDS" pool-name="TestDSPool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
    <connection-url>****</connection-url>
    <driver>com.mysql</driver>
    <pool>
        <prefill>false</prefill>
        <use-strict-min>false</use-strict-min>
        <flush-strategy>FailingConnectionOnly</flush-strategy>
    </pool>
    <security>
        <user-name>****</user-name>
        <password>****</password>
    </security>
</datasource>

部署portlet应用程序工作得很好;但是,当我尝试实际查看portlet时,我得到以下异常:

15:10:05,493 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/survey-portlets].[surveydisplay Servlet]] (ajp--0.0.0.0-8009-3) Servlet.service() for servlet surveydisplay Servlet threw exception: javax.naming.NameNotFoundException: jdbc/surveyDS -- service jboss.naming.context.java.jdbc.surveyDS
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:87)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:173)
    at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:47)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:209)
    at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_26]
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187) [org.springframework.context-3.0.5.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) [org.springframework.beans-3.0.5.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [org.springframework.beans-3.0.5.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [org.springframework.beans-3.0.5.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [org.springframework.beans-3.0.5.RELEASE.jar:]
[ ... stack truncated for brevity ]

我觉得我现在必须遗漏一些非常简单明了的东西,但我不知道它可能是什么。任何建议将不胜感激!

1 个答案:

答案 0 :(得分:0)

将JBoss domain.xml文件中的DataSource jndi-name更改为java:jdbc/surveyDS,您应该没问题。