【问题标题】:JNDI Datasource in GateIn portlet on JBoss 7.1JBoss 7.1 上 GateIn portlet 中的 JNDI 数据源
【发布时间】:2012-05-29 20:30:23
【问题描述】:

我正在尝试在 JBoss 7.1 上的 GateIn 3.2.0 中部署的 portlet 中获取数据源。

首先我在standalone.xml中创建了数据源

            <datasource jta="true" jndi-name="java:jboss/datasources/ccr" pool-name="ccr-pool" enabled="true" use-java-context="false" use-ccm="true">
                <connection-url>jdbc:mysql://localhost:42006/contentrepository</connection-url>
                <driver>com.mysql</driver>
                <security>
                    <user-name>node</user-name>
                </security>
                <statement>
                    <prepared-statement-cache-size>100</prepared-statement-cache-size>
                    <share-prepared-statements>true</share-prepared-statements>
                </statement>
            </datasource>

我还添加了驱动程序和驱动程序模块。

在我的 portlet 中,我尝试使用

访问数据源
dataSource = (DataSource) new InitialContext().lookup("java:jboss/datasources/ccr");

但我只得到一个 javax.naming.NameNotFoundException: Name 'jboss' not found in context ''。

我也尝试用

获取它
dataSource = (DataSource) new InitialContext().lookup("java:comp/env/datasources/ccr");

并将其映射到 web.xml 和 jboss-web.xml 中的以下条目

web.xml:

<resource-ref>
    <description>MySQL DS</description>
    <res-ref-name>datasources/ccr</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

jboss-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
    <resource-ref>
        <res-ref-name>datasources/ccr</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <jndi-name>java:jboss/datasources/ccr</jndi-name>
    </resource-ref>
</jboss-web>

然后我得到 javax.naming.NameNotFoundException: Name 'comp' not found in context ''。

我错过了什么?是否有一些安全设置阻止我的应用程序获取数据源?

奇怪的是,当使用 servlet 时,我可以在同一个 Web 应用程序中获取数据源,但只能在 doGet/doPost 方法中,而不是在 init() 中。

【问题讨论】:

    标签: jboss jndi gatein


    【解决方案1】:

    我在 GateIn 3.3 上遇到了同样的问题。但它没有用 GateIn 3.4M1 复制。当我用谷歌搜索这个错误时,我在 JIRA 中找到了它:https://issues.jboss.org/browse/GTNPORTAL-2511

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-20
      • 2013-09-05
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 2011-12-07
      • 1970-01-01
      • 2012-05-25
      相关资源
      最近更新 更多