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

发布于 2025-01-06 13:42:13 字数 4936 浏览 3 评论 0原文

我在 JBoss 7.0.2 中的数据源 JNDI 查找正常工作时遇到一些问题。基本上,该应用程序应该可以跨多个应用程序服务器部署,因此我想遵守适当的标准。所讨论的应用程序是一个简单的 portlet 应用程序,部署在 Liferay 6.1 中,在 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 ]

我觉得此时我一定错过了一些非常简单且明显的东西,但我不知道它可能是什么。任何建议将不胜感激!

I'm having some issues getting a JNDI lookup of a datasource in JBoss 7.0.2 to work properly. Basically, this application is one that should be deployable across multiple application servers, so I'd like to adhere to appropriate standards. The application in question is a simple portlet application deployed in Liferay 6.1 running in a Jboss managed domain; I've tried various combinations of naming conventions in web.xml, jboss-web.xml, and persistence.xml; all to no avail. My current configuration looks like this:

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>

Datasource definition in ${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>

Deploying the portlet application works just fine; however, when I attempt to actually view the portlet, I get the following exception:

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 ]

I feel like I must be missing something very simple and obvious at this point, but I have no idea what it might be. Any suggestions would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诺曦 2025-01-13 13:42:13

将 JBoss domain.xml 文件中的 DataSource jndi-name 更改为 java:jdbc/surveyDS,这样就可以了。

Change the DataSource jndi-name in the JBoss domain.xml file to java:jdbc/surveyDS, and you should be fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文